Skip to content

Instantly share code, notes, and snippets.

@nucknorris
Forked from eranation/gist:3241616
Created August 27, 2013 11:34
Show Gist options
  • Save nucknorris/6352442 to your computer and use it in GitHub Desktop.
Save nucknorris/6352442 to your computer and use it in GitHub Desktop.
//equivalent of "select count (distinct fieldName) from someTable"
db.someCollection.aggregate([{ $group: { _id: "$fieldName"} },{ $group: { _id: 1, count: { $sum: 1 } } } ])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment