Skip to content

Instantly share code, notes, and snippets.

@srleo
Last active December 19, 2015 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save srleo/5936238 to your computer and use it in GitHub Desktop.
Save srleo/5936238 to your computer and use it in GitHub Desktop.
Basic group-by count using mongodb aggregation
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