Skip to content

Instantly share code, notes, and snippets.

@leopd
Forked from srleo/groupby.js
Created August 28, 2013 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leopd/6367465 to your computer and use it in GitHub Desktop.
Save leopd/6367465 to your computer and use it in GitHub Desktop.
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