Skip to content

Instantly share code, notes, and snippets.

@stevecass
Created March 10, 2015 17:53
Show Gist options
  • Save stevecass/7084098fb1edf42ba9cd to your computer and use it in GitHub Desktop.
Save stevecass/7084098fb1edf42ba9cd to your computer and use it in GitHub Desktop.
Mongoose group by parent
function doSumByGroup() {
var agg = [
{$group: {
_id: "$columnObject",
total: {$sum: 1}
}}
];
Snippet.aggregate(agg, function(err, logs){
if (err) {
handleErrors();
} else {
console.log(logs);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment