Group by name and count
db.simple.aggregate( [ { $group: { _id: "$name", total: { $sum : 1 } } } ] )
{
"result": [
{
"_id": "bar",
"total": 2
},
{
"_id": "foo",
"total": 3
}
],
"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
db.simple.aggregate( [ { $group: { _id: "$name", total: { $sum : 1 } } } ] )
{
"result": [
{
"_id": "bar",
"total": 2
},
{
"_id": "foo",
"total": 3
}
],
"ok": 1
}