# QueryExceededMemoryLimitNoDiskUseAllowed
Full text: `QueryExceededMemoryLimitNoDiskUseAllowed`. A pipeline stage (usually `$sort` or `$group`) needed more than 100MB of RAM and `allowDiskUse` was false.
## Confirm
Run the query with `explain("executionStats")`. Look for a `SORT` stage with no index, or a `$group` over a huge cardinality. The stage doing the heavy in-memory work is the one to fix.
## Fix, in order
1. Index the sort: an index on the sort keys (matching sort direction) lets the query stream in order with no in-memory sort at all. This is the real fix.
2. Reduce the working set: push `$match` earlier, `$project` away unneeded fields before the heavy stage.
3. Only then consider `allowDiskUse: true` on the aggregation. It spills to disk and finishes, but slowly. Treat it as a bandage while the index builds, not the solution.
## Verify
Re-run `explain`: the SORT stage is gone (replaced by an index scan in order), and the query completes with `allowDiskUse` off.