A revenue-by-SKU aggregation with `$group` works fine in staging on a sample collection, then fails in production with an 'exceeded memory limit' error once the collection crosses a certain size. What's actually happening, and is `allowDiskUse: true` the right fix?
$group can't emit a single group until it has seen every document that might belong to it, so it has to buffer its working set in memory rather than streaming through like $match or $project can — and the server enforces a 100 MB limit on that buffer per stage, aborting the aggregation if a stage's buffer grows past it. In staging, the sample collection's groups were small enough to fit; in production, the real collection's groups grew past 100 MB and the exact same pipeline, unchanged, started failing — it's not a new bug, it's the same buffering stage finally being exercised at real scale. allowDiskUse: true lets that one stage spill its working set to temporary files on disk and keep going, which fixes the failure, but it's the honest fix only when there's genuinely no way to shrink what reaches $group first — an earlier $match or a design that reduces the group cardinality is often the actually-correct fix, with allowDiskUse as the fallback when there truly isn't a smaller input available.