Skip to main content

Aggregation Pipeline

Aggregation Pipeline Basics

0:00
LearnStep 1/2

Aggregation Basics

MongoDB Aggregation Pipeline

The aggregation pipeline processes documents through a sequence of stages.

Basic Pipeline Structure

python

Common Pipeline Stages

StagePurpose
$matchFilter documents (like find)
$projectReshape documents, select fields
$groupGroup by field, perform aggregations
$sortOrder documents
$limitLimit number of documents
$skipSkip documents
$unwindDeconstruct array field
$lookupJoin with another collection
$addFieldsAdd new fields
$countCount documents

$match Stage

python

$project Stage

python

sortandsort andlimit

python

Running Aggregation

python