mongodb-aggregation-stages-deep

Parent: MongoDB Aggregation Pipeline · researched 2026-05-28T18:45:10.179Z· 18 sources · 10 concepts · skill mongodb-aggregation-stages-deep

This skill is the deep-dive companion to mongodb-aggregation-pipeline. It

MongoDB Aggregation Stages — Deep Reference

1. `$lookup` — left outer join

1.1 Equality form (`localField`/`foreignField`)

1.2 Pipeline form with `let`

1.3 Atlas Search inside `$lookup` (6.0+)

1.4 Sharded collections

1.5 `$lookup` vs denormalization decision tree

1.6 Common `$lookup` pitfalls

2. `$graphLookup` — recursive single-collection traversal

2.1 Syntax

2.2 Tree / hierarchy patterns

2.3 Category trees and bill-of-materials

2.4 Cycle protection

2.5 Memory and performance

2.6 Common use cases

3. `$facet` — parallel sub-pipelines

3.1 Syntax and structure

3.2 Constraints

3.3 When to reach for `$facet`

3.5 `$facet` vs running pipelines in parallel from the client

4. `$bucket` and `$bucketAuto` — histograms

4.1 `$bucket` — explicit boundaries

4.2 `$bucketAuto` — automatic boundaries

4.4 Histogram + summary together

5. `$out` vs `$merge` — writing pipeline results

5.1 `$out` — wholesale collection replacement

5.2 `$merge` — incremental upsert

5.3 Materialized view refresh patterns

5.4 Idempotency rules

5.5 Pitfalls

6. `$setWindowFields` — window functions

6.1 Anatomy

6.2 Operator catalog

6.3 Ranking semantics

6.6 Derivative and integral for time-series

6.7 Memory limit

7. `$densify` — close gaps in numeric / time ranges

7.1 Syntax

7.2 Hourly observations example

7.3 Numeric densification example

7.4 Rules

8. `$fill` — populate null and missing values

8.1 Methods

8.3 Time-series gap fill (densify + fill)

8.4 `$linearFill` expression (vs `$fill`'s `linear` method)

8.5 Rules

9. `$unionWith` — UNION ALL across collections

9.1 Syntax

9.3 Removing duplicates (`UNION` not `UNION ALL`)

9.4 Rules

9.5 Use cases

10.1 The 100 MB-per-stage rule

10.2 Enabling disk spill

10.3 `explain("executionStats")` for spill detection

10.4 The 16 MB document limit

10.5 Stage ordering for memory and performance

10.6 Sharded aggregation specifics

13. Anti-patterns

15. Sources

Children

Frontier under this node: $bucket-bucketAuto, $densify-$fill, $facet, $graphLookup, $lookup, $merge-$out, $setWindowFields, $unionWith, allowDiskUse-100MB-stage, explain-executionStats-usedDisk

← the whole tree · 3D view· how to read this page