Skip to content
Theory · MongoDB: Aggregation, Indexes and Scaling · lesson 1 of 13

The aggregation pipeline

A pipeline table: $match lets finished orders through, $group sorts them into piles with slips, and only the slips reach $sort

In the previous chapter we found cards in the box with a filter: find returns documents as they are stored. The coffee shop's manager asks something else: how much each city earned, which order is the biggest, how many orders were cancelled. The answer is not documents but totals per group. SQL has GROUP BY for this, and MongoDB has the aggregation pipeline.

In this lesson

  • Pipeline and stages
  • Accumulators
  • Sorting and the first N
  • Several reports at once
  • Common mistake
  • Key points