1, first example analysis of the following MongoDB aggregation operations:
- This operation indicates that the count quantity under each group is counted according to the whoisserver_id field grouping:
Db.anhui.aggregate ({$group: {_id:'$whoisserver _id', total:{$sum:1}})
The results of the query are as follows:
- If the total number of queries:
Db.anhui.aggregate ({$group: {_id:null, total:{$sum: 1}})
- The following query filters and then counts based on criteria
db.anhui.aggregate {$match: {mx:{$exists: 1}}},{$group: {_id: ' $whoisserver _id ', total:{ $sum: 1}})
- First filter the data equivalent to the where operation in the SQL statement, then group Count, and then match the information with a quantity greater than 30
db.anhui.aggregate {$match: {mx:{$exists: 1}}},{$group: {_id: ' $whoisserver _id ', total:{ $sum: 1}}},{$match: {total:{$gte: 30}})
The following is the data to be queried
Inquire
db.anhui.aggregate {$match: {mx:{$exists: 1}}},{$group: {_id: ' $mx. brand_id ', total:{ $sum: 1}})
MongoDB Aggregation Operations