All the elements - sum
We can also use an arbitrary string instead of the null
db.simple.aggregate( [ { $group: { _id: "total", total: { $sum : "$cnt" } } } ])
{
"result": [
{
"_id": "total",
"total": 26
}
],
"ok": 1
}
Press ← or → to navigate between chapters
Press S or / to search in the book
Press ? to show this help
Press Esc to hide this help
We can also use an arbitrary string instead of the null
db.simple.aggregate( [ { $group: { _id: "total", total: { $sum : "$cnt" } } } ])
{
"result": [
{
"_id": "total",
"total": 26
}
],
"ok": 1
}