MongoDB Aggregate Sum Each Key on a Subdocument
问题 I have multiple documents with this schema, each document is per product per day: { _id:{}, app_id:'DHJFK67JDSJjdasj909', date:'2014-08-07', event_count:32423, event_count_per_type: { 0:322, 10:4234, 20:653, 30:7562 } } I would like to get the sum of each event_type for a particular date_range. This is the output I am looking for where each event type has been summed across all the documents. The keys for event_count_per_type can be anything, so I need something that can loop through each of