Mongodb search aggregate SUM
- find aggregate and where
db.cabinet.aggregate(
[
{
$group:
{
_id: { },
totalAmount: { $sum: "$cabinetBoxTotal" },
count: { $sum: 1 }
}
}
]
)
db.cabinet.aggregate(
[
{ $match : { cabinetName : "中国农业大学西校区2号柜"} },
{
$group:
{
_id: {},
totalAmount: { $sum: "$cabinetBoxTotal" },
count: { $sum: 1 }
}
}
]
)