Skip to content

Instantly share code, notes, and snippets.

View nucknorris's full-sized avatar

Sebastian Nuck nucknorris

View GitHub Profile
//equivalent of "select count (distinct fieldName) from someTable"
db.someCollection.aggregate([{ $group: { _id: "$fieldName"} },{ $group: { _id: 1, count: { $sum: 1 } } } ])