# The Aggregation Pipeline

A report is data on a conveyor belt: each stage does one job and hands its documents to the next. Filter with $match, total and average with $group, and shape, sort and trim the result.

Updated: November 19, 2026

## [Pipeline Basics](https://www.ask-codey.com/courses/mongodb-in-depth/topics/mongodb-pipeline-basics)

1. [The Aggregation Pipeline: Data on a Conveyor Belt](https://www.ask-codey.com/lessons/mongodb-aggregation-pipeline) (Apprentice): An aggregation pipeline sends a collection's documents through a list of stages, each doing one job, so the database can answer report questions that find can't, starting with $match to choose the documents and $count to count them.
2. [$group: Totals, Counts and Averages](https://www.ask-codey.com/lessons/mongodb-aggregation-group) (Journeyman): The $group stage sorts documents into groups by the value of a field, or puts them all in one group, and computes each group's total, count, average, smallest, biggest and first value with accumulators.
3. [Shaping the Report: $project, $set, $sort and $limit](https://www.ask-codey.com/lessons/mongodb-aggregation-project-sort-limit) (Journeyman): Four stages turn a pipeline's correct answer into a report someone can read, $sort and $limit for the top few, $project to choose and rename fields, and $set to compute new ones with expressions such as $multiply and $round, and the order of the stages changes what comes out.

## [Exercise: Sales by Category](https://www.ask-codey.com/courses/mongodb-in-depth/topics/mongodb-exercise-sales-by-category)

1. [Exercise: Sales by Category](https://www.ask-codey.com/lessons/exercise-mongodb-sales-by-category) (Journeyman): Write five aggregation pipelines for Riverbend Bike Shop's sales dashboard, from the revenue of each category to the three biggest orders, and let the tests run each one on a year of orders and check its rows.

Source: https://www.ask-codey.com/courses/mongodb-in-depth/chapters/the-aggregation-pipeline-in-mongodb
