Advertisement
Guest User

Untitled

a guest
Jul 26th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.32 KB | None | 0 0
  1. //equivalent of MySQL "SELECT COUNT(*) AS `count`, `fieldName` FROM `someTable` GROUP BY `fieldName
  2. db.someCollection.aggregate([{"$group" : {_id:"$fieldName", count:{$sum:1}}}]);
  3.  
  4. //as above but ordered by the count descending
  5. db.someCollection.aggregate([{"$group" : {_id:"$fieldName", count:{$sum:1}}}, {$sort:{'count':-1}}]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement