Created
August 2, 2012 22:51
-
-
Save eranation/3241616 to your computer and use it in GitHub Desktop.
MongoDB Aggregation Framework way for "select count (distinct fieldName) from someTable" for large collections
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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
This seems cuter (I added a match too)