Last active
December 19, 2015 09:49
-
-
Save srleo/5936238 to your computer and use it in GitHub Desktop.
Basic group-by count using mongodb aggregation
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
count_by = function(collection,field) { | |
return collection.aggregate({ | |
$group: { | |
_id: "$" + field, | |
count: { $sum: 1 } | |
} | |
}) | |
} | |
count_by(db.vid10,'char'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment