$group Accumulators
Accumulators include $sum, $avg, $min, $max, $first, $last, $push and $addToSet. Group by null to summarise everything.
Example
db.orders.aggregate([
{ $group: { _id: null, count: { $sum: 1 }, avg: { $avg: "$amount" }, max: { $max: "$amount" } } }
])Exercise
Average.
{ $: "$amount" }
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.