db.restaurants.aggregate(
[
{ $match: { "borough": "Queens", "cuisine": "Brazilian" } },
{ $group: { "_id": "$address.zipcode" , "count": { $sum: 1 } } }
]
);
高洛峰2017-04-28 09:06:16
http://docs.mongodb.org/manual/reference/operator/aggregation/sum/
Sum by expression value 1 represents 1
世界只因有你2017-04-28 09:06:16
According to the conditions of the group, if one condition is met, add 1, that is, count is the number of each zipcode in the group