I am using mongodb 2.2. I would like to use the new aggregation structure to execute queries on my documents, but the elements are arrays.
Here is an example of my $ project project:
{ "type" : [ "ads-get-yyy", "ads-get-zzz" ], "count" : [ NumberLong(0), NumberLong(10) ], "latency" : [ 0.9790918827056885, 0.9790918827056885 ] }
I want to group by type, so for "ads-get-yyy" you need to know how much the average is and how much is the average delay.
I would like to have something similar to the following query, but this works inside the elements of each array:
db.test.aggregate( { $project : { "type" : 1, "count" : 1, "latency" : 1 } },{ $group : { _id: {type : "$type"}, count: {$avg: "$count"}, latency: {$avg: "$latency"} } });
source share