Pinned Compass preview cap injection and collection-count guard
Parent: Compass aggregation preview sampling versus full pipeline execution · Published reference · snapshot 2026-11-02
↓ Facts as markdownall context files
Source-anchored research for Pinned Compass preview cap injection and collection-count guard. Run status: COMPLETED.
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
- In the cited pinned implementation, `createPreviewAggregation` permits added input limits when `options.totalDocumentCount` is falsy or exceeds the effective sample size computed from `options.sampleSize` and `DEFAULT_SAMPLE_SIZE`. A truthy count at or below that size suppresses those input limits; the fixture with `totalDocumentCount: 10` retains `$group` and `$bucket` without prepended limits while retaining the final preview limit. An omitted or zero count permits insertion before qualifying full-scan stages, including when a zero count equals an effective sample size of zero. The zero-count boundary is a deduction from the shown predicate. (high confidence) [source 1] [source 2]
- In the cited pinned implementation, `createPreviewAggregation` loops over the supplied top-level stages and, when its collection-count predicate allows it, inserts a separate `$limit` immediately before each operator classified in `FULL_SCAN_OPS`. The source fixture for `$group` followed by `$bucket` asserts an input limit before each stage, then a final preview limit; these are source assertions, not tests executed for this research. (high confidence) [source 1] [source 2] [source 3]
- The final preview-limit guard is independent of the collection-count guard. It appends `$limit: options.previewSize ?? DEFAULT_PREVIEW_LIMIT` unless the final constructed stage operator belongs to `REQUIRED_AS_FIRST_STAGE_OPS`. The index-statistics fixture for a sole stage classified as required first expects that stage alone, while the empty-pipeline fixture expects the final limit. (high confidence) [source 1] [source 2] [source 3]
- The helper rejects a pipeline when `isLastStageOutputStage(pipeline)` is true, before constructing preview stages. Its fixture expects a pipeline ending in `$out` to throw. A separate fixture explicitly expects a non-final `$out` followed by `$sort` to pass through this helper and receive the final preview limit; that assertion establishes helper transformation behavior, not server acceptance or safe execution of that pipeline. (medium confidence) [source 1] [source 2]
Comparisons and alternatives
- Input limits use `options.sampleSize ?? DEFAULT_SAMPLE_SIZE`; the appended limit independently uses `options.previewSize ?? DEFAULT_PREVIEW_LIMIT`. These nullish fallbacks preserve explicitly supplied zero values rather than replacing them by truthiness, and the helper contains no option-range validation. This describes transformation code only, not server acceptance of those values. This helper reads the supplied collection count rather than querying it. (low confidence) [source]
Facts and statements
- In the pinned stage utilities, `getStageOperator` returns the first key of `stage ?? {}`. `getLastStageOperator` inspects the final array element and substitutes an empty string for an absent operator. `isLastStageOutputStage` applies `isOutputStage` only to that final operator, and `isOutputStage` checks the `OUT_OPERATOR_NAMES` set. This file imports `OUT_STAGES` from `@mongodb-js/mongodb-constants` and constructs that set from each entry's `stage.value`. The preview helper uses these operator helpers for its injection and final-stage guards. These helper bodies inspect top-level keys without recursively inspecting nested pipelines. (medium confidence) [source 1] [source 2]
Children
- No children recorded.