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

More aggregation commands

All aggregation commands · MongoDB 8 cheatsheet

Was this page helpful?