← MongoDB learning path
MongoDB · Module 6 of 10

Aggregation pipeline

Transform and analyse data with stages.

📖 Key ideas

  1. aggregate([ stage1, stage2, ... ]) processes documents step by step.
  2. $match filters; $group groups and sums.
  3. $project reshapes; $sort orders; $limit trims.
  4. $lookup joins another collection; $unwind flattens arrays.
  5. Use for reports: totals, averages, counts.
💡 Real-life example: The pipeline is a factory line: each station (stage) changes the product before passing it on.
$matchFilter stage
$groupGroups and calculates
$unwindSplits an array into documents
$projectReshapes fields