Pipeline Basics

Pipeline Basics: The Aggregation Pipeline: Data on a Conveyor Belt, $group: Totals, Counts and Averages, Shaping the Report: $project, $set, $sort and $limit.

Updated

  1. The Aggregation Pipeline: Data on a Conveyor Belt (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 (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 (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.