MongoDB Error: Sort exceeded memory limit of 33554432 bytes
In-memory sort without a supporting index exceeded the 32 MB stage limit.
Runs locally in browser
Free · No login
Independently Verified 2026-11-25
v4.0.0
Identifier: MongoDB Error
Platform: Databases
Common Root Causes:
- In-memory sort without a supporting index exceeded the 32 MB stage limit.
Interactive Diagnostic Checklist
Verified Solutions:
- Create a compound index matching filter + sort order, or enable `allowDiskUse(true)` for batch aggregations.
Safe Diagnostic Command:
db.<coll>.find(...).sort(...).explain("executionStats")Warning: Verify configuration changes in staging or with dry-run flags (e.g. nginx -t) before reloading production services.
Technical Explanation
In-memory sort without a supporting index exceeded the 32 MB stage limit. Recommended diagnostic: `db.<coll>.find(...).sort(...).explain("executionStats")`. Remediation: Create a compound index matching filter + sort order, or enable `allowDiskUse(true)` for batch aggregations.
Worked Examples
- Run `db.<coll>.find(...).sort(...).explain("executionStats")` to confirm root cause before applying the fix.
Limitations & Assumptions
- Always test configuration changes in staging or with dry-run flags (e.g. `nginx -t`) before reloading production services.
Source References & Verification
Resource ID: err-mongodb-sort-exceeded-memory · Independently verified: 2026-11-25