Aggregation pipeline: stages like $match, $group, $sort, and $project chain together. Documents flow through in order, enabling complex analytics directly in the database.
2 / 5
What does the $group stage do?
$group: similar to SQL's GROUP BY. { $group: { _id: "$status", total: { $sum: "$amount" } } } groups orders by status and sums each group's amount, returning one document per distinct status.
3 / 5
What is the purpose of $lookup?
$lookup: lets a pipeline join documents from a second collection on matching fields. It adds an array of joined documents to each input document, enabling relational-style queries within MongoDB.
4 / 5
What does $unwind do to an array field?
$unwind: if a document has tags: ["a","b","c"], $unwind: "$tags" emits three documents each with a single tags value. It is often paired with $group to aggregate on array contents.
5 / 5
What performance technique should you apply early in a pipeline?
Early $match: filtering documents early shrinks the working set for all downstream stages. If $match can use an index it is especially powerful, whereas placing it late wastes computation on documents that will be discarded.