MongoDB 8 · Aggregation
Group and total
Sum order amounts per status.
db.orders.aggregate([
{ $group: { _id: "$status", total: { $sum: "$amount" }, count: { $sum: 1 } } }
])
Official MongoDB 8 documentation
MongoDB 8 · Aggregation
Sum order amounts per status.
db.orders.aggregate([
{ $group: { _id: "$status", total: { $sum: "$amount" }, count: { $sum: 1 } } }
])
Official MongoDB 8 documentation
Was this page helpful?