Skip to content

Instantly share code, notes, and snippets.

@leopd
Forked from srleo/groupby.js
Created August 28, 2013 15:37
Show Gist options
  • 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