<!-- llms-explorer concept facts · https://llms-explorer.com/tree/blocking-sort-memory-limit-and-allowdiskuse/ · pack 2026-10-31 · ~1207 tokens -->

# Blocking sort memory limit and allowDiskUse

> Source-anchored research for Blocking sort memory limit and allowDiskUse. Run status: COMPLETED.

Parent: [SORT_MERGE and $in sort expansion](https://llms-explorer.com/tree/sort-merge-and-in-sort-expansion/) · 6 facets · 11 facts · page: https://llms-explorer.com/tree/blocking-sort-memory-limit-and-allowdiskuse/

## How it works

- The aggregation limits documentation says profiler and diagnostic log messages include a usedDisk indicator when an aggregation stage writes temporary files because of memory restrictions. This indicates that some stage spilled; it does not alone identify the sort stage. (low confidence) — [source](https://www.mongodb.com/docs/manual/core/aggregation-pipeline-limits.md)
- Spill files consume storage for the pipeline execution's duration; on Atlas, temporary-file growth can trigger storage auto-scaling to a higher storage tier. (low confidence) (verified as of 2026-10-30) — [source](https://www.mongodb.com/docs/manual/core/views.md)
- Spring Data MongoDB AggregationOptions.Builder starts with DiskUse.DEFAULT; isAllowDiskUseSet() distinguishes that from an explicit choice, and serialization adds allowDiskUse only when it is set. Calling Builder.allowDiskUse(boolean) supplies an explicit disk-use choice. (low confidence) (verified as of 2026-10-30) — [source](https://github.com/spring-projects/spring-data-mongodb/blob/main/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationOptions.java)

## How-to and procedures

- Use explain to check for a SORT stage when diagnosing a blocking sort. cursor.allowDiskUse() has no effect on sorts answered using an index or non-indexed sorts requiring less than 100 MB; merely returning a large result set does not establish that this option is useful. (high confidence) — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.allowDiskUse.md)

## Measurements and reference values

- Starting in MongoDB 6.0, allowDiskUseByDefault controls default spilling for stages exceeding 100 MB. With the parameter true, allowDiskUse:false prohibits spilling for an individual find or aggregate; with it false, allowDiskUse:true enables spilling for that command. The cursor documentation identifies true as the parameter default. (high confidence) (verified as of 2026-10-14) — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.allowDiskUse.md)

## Problems, failure modes and limitations

- A sort combined with limit(k) can retain only the best k results in memory; if the retained results exceed the sort memory threshold, the operation still needs permission to spill or it fails. (low confidence) — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.sort.md)
- Atlas documentation says Free and Flex clusters do not support temporary-file writes and ignore allowDiskUse, behaving as if it were false. The same page separately lists a 32 MB in-memory sort limit for Free clusters; it does not establish that this numeric limit applies to Flex. (low confidence) (verified as of 2026-10-14) — [source](https://www.mongodb.com/docs/atlas/reference/free-shared-limitations.md)

## Comparisons and alternatives

- The 100 MB aggregation restriction applies per stage, including an unindexed $sort, rather than being a single 100 MB budget for the entire pipeline. (high confidence) — [source](https://www.mongodb.com/docs/manual/core/aggregation-pipeline-limits.md)
- For the general server behavior documented here, a non-index-supported blocking sort is subject to a 100 MB memory threshold; allowDiskUse permits eligible operations to write temporary files beyond it rather than simply raising the in-memory allowance. Deployment restrictions can override this behavior. (medium confidence) — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.allowDiskUse.md)

## Facts and statements

- Mongoose Query.allowDiskUse(v) sets the allowDiskUse query option; calling it without arguments sets true. Its documentation presents this as a workaround for QueryExceededMemoryLimitNoDiskUseAllowed, while the server documentation scopes its effect to eligible large non-indexed sorts. (high confidence) (verified as of 2026-10-30) — [source](https://mongoosejs.com/docs/api/query.html)
- An in-memory storage engine does not by itself guarantee that aggregation temporary data stays in RAM. SERVER-36388 documents that the external sorter can spill despite the engine being in-memory; an independent user reported local-drive I/O with allowDiskUse:true on Percona In-Memory 5.0.22 after a $group aggregation failed without it. The user observation concerns $group and does not establish every current sort implementation. (medium confidence) — [source](https://jira.mongodb.org/browse/SERVER-36388)
