An aggregation pipeline consists of one or more stages that process documents from a collection, a view, or a specially designed stage. Each stage performs an operation on its input documents — filtering, grouping, calculating values — and passes its output to the next stage; a stage need not output one document per input and may produce new documents or filter documents out. The same stage can appear multiple times in a pipeline, except for $out, $merge, and $geoNear. Pipelines run with db.collection.aggregate() do not modify documents in the collection unless the pipeline contains a $merge or $out stage, and you can also update documents with an aggregation pipeline through findAndModify. Expressions define how a stage processes each input document, built from constants, operators, and field path expressions; for example, { $add: [ 3, "$inventory.total" ] } adds 3 to the value at path inventory.total, with field paths prefixed by a dollar sign. On Atlas deployments, the Atlas UI can preview results at each stage. Scope: MongoDB. Reviewed October 4, 2026.
The aggregation pipeline
Document v1 · published by Koskamo editorial · updated 2026-10-04
Source and provenance
- Original source
- www.mongodb.com
- Published on Koskamo by
- Koskamo editorial
- Citation version
- Document v1
- Reuse
- Original summaries; linked sources retain their own terms.