$group
Group and total values.
Example
db.sales.aggregate([
{ $group: { _id: "$region", n: { $sum: 1 }, avg: { $avg: "$amount" } } }
])Exercise
Count each.
n: { : 1 }
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.