Wednesday 2 April 2014

find the sum in mongoDB using nodejs

 db.collectionName.aggregate([{$match: {whereColumn: value}}, {$group: {_id: "$fieldToGroup", "total_budget": {$sum: "$column.amount"}}}], function(err, sum) {
console.log(sum[0].total_budget);
});

No comments:

Post a Comment