Skip to content

Aggregation stages

Stages transform a list of documents. Expression operators calculate a value inside a document. The same name can have different syntax in these contexts.

These pages describe the 21 registered Core stages. They are not a list of Studio palette steps. For the authoring UI, use the Flow step reference. SrotaX normally processes one request document; use array expressions such as $map and $sortArray to transform its lists.

Each page includes a runnable pipeline, actual Core output, and implementation limits. The stage examples are separate from the 6,495-case expression parity suite.

Stage Purpose
$match Retains documents that satisfy a condition object.
$addFields Adds or replaces fields while retaining other fields.
$set Adds or replaces fields while retaining other fields.
$project Builds each output document from explicitly selected or computed fields.
$unset Removes named fields from each document.
$limit Keeps the first N documents.
$skip Drops the first N documents.
$sort Orders documents by one or more fields.
$unwind Produces one document for each element of an array field.
$replaceRoot Replaces the entire document with an object expression.
$replaceWith Replaces the entire document with an object expression.
$group Combines documents sharing a grouping key and computes accumulator outputs.
$sortByCount Counts documents per grouping value and sorts groups by descending count.
$bucket Groups numeric values into explicit lower-inclusive, upper-exclusive ranges.
$bucketAuto Divides the numeric value range into equal-width buckets.
$facet Runs named child pipelines over the same input list and collects their results.
$lookup Adds matching records from a host-provided in-memory dataset.
$densify Inserts documents for missing numeric or date positions.
$fill Replaces null or missing values using a value expression or interpolation.
$setWindowFields Adds values computed over an ordered partition of documents.
$subPipeline Executes inline child pipelines or resolves child references through the caller’s execution context.