The aggregation pipeline transforms documents through stages, like a Unix pipe. Stage SQL analogue $match WHERE (put it first to use indexes) $project / $addFields / $set SELECT expressions $group GROUP BY with $sum, $avg, $min, $max, $push, $addToSet $sort, $limit, $skip ORDER BY, LIMIT, OFFSET $unwind one document per array element $lookup LEFT OUTER JOIN $facet several sub-pipelines on the same input $bucket histograms $merge / $out write results to a collection (materialised views) Field paths use "$field"; stages can use expression operators like $multiply, $cond, $dateToString.
Key Takeaways
Start pipelines with $match (and $sort) so they can use indexes.
$unwind + $group is the standard way to aggregate array contents.
$lookup joins collections; keep it off hot paths where possible.
$facet computes several reports from one scan of the input.