Window Functions ($setWindowFields)
Parent: MongoDB Aggregation Pipeline · Published reference · snapshot 2026-10-15
↓ Facts as markdownall context files
Depth-first rabbithole dossier for Window Functions ($setWindowFields); source-anchored research pack.
These notes link each claim to its source. Some citations identify archived research reports that are no longer hosted on this site. A published reference means the content is available; it does not certify independent review or accuracy.Read the editorial policy and follow the sources before relying on a claim.
Problems, failure modes and limitations
- [low] Rank operators use an implicit window and return an error if a window option is specified. Sources: https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields.md [source]
- [low] Before MongoDB 5.3, the $setWindowFields stage cannot be used within transactions or with "snapshot" read concern. (verified as of 2026-10-15) Sources: https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields.md [source]
Facts and statements
- [low] A feature related to window functions is noted as new in version 8.3. (verified as of 2026-10-15) Sources: https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields.md [source]
- [low] The returned value behavior for $count and $sum operators is defined in the context of window functions. Sources: https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields.md [source]
- [low] The returned value behavior for $addToSet and $push operators is defined in the context of window functions. Sources: https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields.md [source]
- [medium] The $setWindowFields stage groups documents into windows and applies one or more operators to the documents in each window, a feature introduced in MongoDB version 5.0. (verified as of 2026-10-15) Sources: https://www.mongodb.com/docs/manual/reference/mql/aggregation-stages.md, https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields.md [source]
- [low] For range windows, only numbers in the specified range are included, while missing, undefined, and null values are excluded. Sources: https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields.md [source]
- [low] For time range windows (range windows with a unit), only date and time types are included in the window. Sources: https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields.md [source]
- [low] For time range windows, numeric boundary values must be integers, such as 2 hours, but not fractional values like 1.5 hours. Sources: https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields.md [source]
- [low] The $setWindowFields stage does not guarantee the order of the returned documents. Sources: https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields.md [source]
- [low] Running explain on a $setWindowsFields operation produces output containing a peakTrackedMemBytes field that indicates the maximum number of bytes of tracked memory. (verified as of 2026-10-15) Sources: https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields.md [source]
- [low] The sortBy option is required for the $linearFill and $shift operators. Sources: https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields.md [source]
- [low] It is safe to run the $setWindowFields stage on each shard independently as long as each partition lives on a single shard, meaning the shard key must be at least as coarse as the partitionBy expression or constant within each partition. Sources: https://jira.mongodb.org/browse/SERVER-56583 [source]
- [low] The $setWindowFields stage with a partitionBy is converted to a $sort followed by $_internalSetWindowFields before optimization, and pushing down the $sort would not be valid. Sources: https://jira.mongodb.org/browse/SERVER-56583 [source]
- [low] The $setWindowFields stage allows applying aggregation operations that span multiple documents. Sources: https://www.practical-mongodb-aggregations.com/examples/time-series/state-change-boundaries.html [source]
- [low] Combined with the $shift operator, the $setWindowFields stage allows peeking at preceding or following documents to bring their content into the current document. Sources: https://www.practical-mongodb-aggregations.com/examples/time-series/state-change-boundaries.html [source]
- [low] Using $shift relies on documents being partitioned and sorted, which the containing $setWindowFields stage enforces. Sources: https://www.practical-mongodb-aggregations.com/examples/time-series/state-change-boundaries.html [source]
- [low] A pattern uses $setWindowFields with partitionBy on deviceID and sortBy on timestamp to apply $shift operators that retrieve previous and next state values. Sources: https://www.practical-mongodb-aggregations.com/examples/time-series/state-change-boundaries.html [source]
Related concepts
- setWindowFields — is a part of Window Functions ($setWindowFields)
- Window — is a part of Window Functions ($setWindowFields)
- Functions — is a part of Window Functions ($setWindowFields)
Children
- No children recorded.