Aggregation Pipeline
aggregate runs documents through stages such as $match, $group, $sort and $project. Each stage feeds the next.
Example
db.orders.aggregate([
{ $match: { status: "paid" } },
{ $group: { _id: "$customer", total: { $sum: "$amount" } } },
{ $sort: { total: -1 } }
])Exercise
Group stage.
{ $: { _id: "$customer" } }
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.