<!-- llms-explorer concept facts · https://llms-explorer.com/tree/pipeline-stages-reference/ · pack 2026-10-15 · ~2673 tokens -->

# Pipeline Stages Reference

> Depth-first rabbithole dossier for Pipeline Stages Reference; source-anchored research pack.

Parent: [MongoDB Aggregation Pipeline](https://llms-explorer.com/tree/mongodb-aggregation-pipeline/) · 6 facets · 28 facts · page: https://llms-explorer.com/tree/pipeline-stages-reference/

## Definitions

- [low] The $queryStats aggregation stage is unsupported and is not guaranteed to be stable in a future release. Sources: https://www.mongodb.com/docs/manual/reference/mql/aggregation-stages.md — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/pipeline-stages-reference-1d1d037d01/rabbithole-synthesis.md#troubleshooting`

## Structure and components

- [low] The $group stage supports certain expressions allowing users to perform arithmetic, array, boolean, and other operations as part of the aggregation pipeline. Sources: https://studio3t.com/knowledge-base/articles/mongodb-aggregation-framework/ — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/pipeline-stages-reference-1d1d037d01/rabbithole-synthesis.md#core`

## How it works

- [low] When using Stable API V1, only the count field is available in the $collStats stage; all other $collStats fields are not available. (verified as of 2026-10-15) Sources: https://www.mongodb.com/docs/manual/reference/command/aggregate.md — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/pipeline-stages-reference-1d1d037d01/rabbithole-synthesis.md#core`
- [low] The explain field is not available in Stable API V1, and including it causes the server to return an APIStrictError. (verified as of 2026-10-15) Sources: https://www.mongodb.com/docs/manual/reference/command/aggregate.md — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/pipeline-stages-reference-1d1d037d01/rabbithole-synthesis.md#core`
- [low] When the MongoDB server closes a session, it also kills any in-progress operations and open cursors associated with that session. Sources: https://www.mongodb.com/docs/manual/reference/command/aggregate.md — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/pipeline-stages-reference-1d1d037d01/rabbithole-synthesis.md#troubleshooting`

## Measurements and reference values

- [low] The $changeStreamSplitLargeEvent stage splits large change stream events that exceed 16 MB into smaller fragments returned in a change stream cursor. Sources: https://www.mongodb.com/docs/manual/reference/mql/aggregation-stages.md — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/pipeline-stages-reference-1d1d037d01/rabbithole-synthesis.md#core`

## Problems, failure modes and limitations

- Fact 1 states MongoDB limits the number of aggregation pipeline stages to 1000, while Fact 44 states there is no limit to the number of stages used in the query. Sources: https://www.mongodb.com/docs/manual/core/aggregation-pipeline-limits.md, https://studio3t.com/knowledge-base/articles/mongodb-aggregation-framework/ — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/pipeline-stages-reference-1d1d037d01/rabbithole-synthesis.md#disagreements`
- [low] There is no limit to the number of stages used in the query, or how they are combined. Sources: https://studio3t.com/knowledge-base/articles/mongodb-aggregation-framework/ — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/pipeline-stages-reference-1d1d037d01/rabbithole-synthesis.md#core`
- [low] You cannot use the $graphLookup stage within a transaction while targeting a sharded collection. Sources: https://www.mongodb.com/docs/manual/reference/operator/aggregation/graphLookup.md — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/pipeline-stages-reference-1d1d037d01/rabbithole-synthesis.md#antipatterns`

## Facts and statements

- [low] All stages except $out, $merge, $geoNear, $changeStream, and $changeStreamSplitLargeEvent can appear multiple times in a pipeline; $out and $merge must also be the last stage. Sources: https://www.mongodb.com/docs/manual/reference/mql/aggregation-stages.md — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/pipeline-stages-reference-1d1d037d01/rabbithole-synthesis.md#core`
- [low] MongoDB limits the number of aggregation pipeline stages allowed in a single pipeline to 1000. Sources: https://www.mongodb.com/docs/manual/core/aggregation-pipeline-limits.md — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/pipeline-stages-reference-1d1d037d01/rabbithole-synthesis.md#core`
- [low] The $changeStream stage can only occur once in an aggregation pipeline and it must occur as the first stage. Sources: https://www.mongodb.com/docs/manual/reference/mql/aggregation-stages.md — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/pipeline-stages-reference-1d1d037d01/rabbithole-synthesis.md#core`
- [low] You can only use $changeStreamSplitLargeEvent in a $changeStream pipeline and it must be the final stage in the pipeline. Sources: https://www.mongodb.com/docs/manual/reference/mql/aggregation-stages.md — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/pipeline-stages-reference-1d1d037d01/rabbithole-synthesis.md#core`
- [low] The $count stage provides an easy way to check the number of documents obtained in the output of the previous stages of the pipeline. Sources: https://studio3t.com/knowledge-base/articles/mongodb-aggregation-framework/ — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/pipeline-stages-reference-1d1d037d01/rabbithole-synthesis.md#core`
- [low] You must use the aggregate command with the cursor option unless the command includes the explain option. Sources: https://www.mongodb.com/docs/manual/reference/command/aggregate.md — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/pipeline-stages-reference-1d1d037d01/rabbithole-synthesis.md#core`
- [low] To indicate a cursor with the default batch size, specify cursor: {}, while a non-default batch size uses cursor: { batchSize: <num> }. Sources: https://www.mongodb.com/docs/manual/reference/command/aggregate.md — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/pipeline-stages-reference-1d1d037d01/rabbithole-synthesis.md#core`
- [low] The { cursor: { batchSize: 0 } } document specifies the size of the initial batch size and indicates an empty first batch. Sources: https://www.mongodb.com/docs/manual/reference/command/aggregate.md — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/pipeline-stages-reference-1d1d037d01/rabbithole-synthesis.md#core`
- [low] If a session is idle for longer than 30 minutes, the MongoDB server marks that session as expired and may close it at any time. Sources: https://www.mongodb.com/docs/manual/reference/command/aggregate.md — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/pipeline-stages-reference-1d1d037d01/rabbithole-synthesis.md#core`
- [low] The querySettings document accepts the following fields: indexHints, queryFramework, reject, comment, queryKnobs, and maxTimeMS. (verified as of 2026-10-15) Sources: https://www.mongodb.com/docs/manual/reference/command/aggregate.md — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/pipeline-stages-reference-1d1d037d01/rabbithole-synthesis.md#core`
- [low] The $vectorSearch stage is only available for MongoDB Atlas clusters running MongoDB v6.0.11 or higher, and is not available for self-managed deployments. (verified as of 2026-10-15) Sources: https://www.mongodb.com/docs/manual/reference/mql/aggregation-stages.md — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/pipeline-stages-reference-1d1d037d01/rabbithole-synthesis.md#core`
- [low] The $graphLookup stage performs a recursive search on a collection, with options for restricting the search by recursion depth and query filter. Sources: https://www.mongodb.com/docs/manual/reference/operator/aggregation/graphLookup.md — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/pipeline-stages-reference-1d1d037d01/rabbithole-synthesis.md#core`
- [low] Setting the maxDepth field to 0 in $graphLookup is equivalent to a non-recursive $graphLookup search stage. Sources: https://www.mongodb.com/docs/manual/reference/operator/aggregation/graphLookup.md — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/pipeline-stages-reference-1d1d037d01/rabbithole-synthesis.md#core`
- [low] The $graphLookup stage does not return sorted results. Sources: https://www.mongodb.com/docs/manual/reference/operator/aggregation/graphLookup.md — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/pipeline-stages-reference-1d1d037d01/rabbithole-synthesis.md#core`
- [low] As of Version 3.4, MongoDB supports faceted classification by using the Aggregation Framework. (verified as of 2026-10-15) Sources: https://docs.spring.io/spring-data/mongodb/reference/mongodb/aggregation-framework.html — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/pipeline-stages-reference-1d1d037d01/rabbithole-synthesis.md#core`
- [low] A sort by count operation is equivalent to the BSON: { $group: { _id: <expression>, count: { $sum: 1 } } }, { $sort: { count: -1 } }. Sources: https://docs.spring.io/spring-data/mongodb/reference/mongodb/aggregation-framework.html — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/pipeline-stages-reference-1d1d037d01/rabbithole-synthesis.md#core`
- [low] As of MongoDB 3.6, it is possible to exclude fields from the projection by using a conditional expression. (verified as of 2026-10-15) Sources: https://docs.spring.io/spring-data/mongodb/reference/mongodb/aggregation-framework.html — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/pipeline-stages-reference-1d1d037d01/rabbithole-synthesis.md#core`
- [low] The same behavior occurs with all grouping stages, specifically $bucket, $bucketAuto, $count, and $sortByCount. Sources: https://www.practical-mongodb-aggregations.com/guides/sharding.html — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/pipeline-stages-reference-1d1d037d01/rabbithole-synthesis.md#core`
- [low] The $out stage must be the last stage in the pipeline. Sources: https://studio3t.com/knowledge-base/articles/mongodb-aggregation-framework/ — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/pipeline-stages-reference-1d1d037d01/rabbithole-synthesis.md#core`

## Related concepts

- Reference — is a part of Pipeline Stages Reference
- Pipeline — is a part of Pipeline Stages Reference
- Stages — is a part of Pipeline Stages Reference
