Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //equivalent of MySQL "SELECT COUNT(*) AS `count`, `fieldName` FROM `someTable` GROUP BY `fieldName
- db.someCollection.aggregate([{"$group" : {_id:"$fieldName", count:{$sum:1}}}]);
- //as above but ordered by the count descending
- db.someCollection.aggregate([{"$group" : {_id:"$fieldName", count:{$sum:1}}}, {$sort:{'count':-1}}]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement