- $group
- $sum
Group by name and sum - $sum
db.simple.aggregate( [ { $group: { _id: "$name", total: { $sum : "$cnt" } } } ]) { "result": [ { "_id": "bar", "total": 14 }, { "_id": "foo", "total": 12 } ], "ok": 1 }
db.simple.aggregate( [ { $group: { _id: "$name", total: { $sum : "$cnt" } } } ]) { "result": [ { "_id": "bar", "total": 14 }, { "_id": "foo", "total": 12 } ], "ok": 1 }