MongoServerError: Executor error during find command :: caused by :: Sort exceeded memory limit of 104857600 bytes, but did not opt in to external sorting
A find().sort() without a supporting index had to sort too much data in memory.
Executor error during find command :: caused by :: Sort exceeded memory limit of 104857600 bytes, but did not opt in to external sortingSort operation used more than the maximum 33554432 bytes of RAM. Add an index, or specify a smaller limitOperationFailed: Sort exceeded memory limitQueryExceededMemoryLimitNoDiskUseAllowed find sort Meaning
Create an index matching the sort (and filter): e.g. { status: 1, createdAt: -1 } for find({status}).sort({createdAt:-1}). Add limit() and projections. allowDiskUse(true) on find (MongoDB 4.4+) works as a stop-gap.
Common causes
- Sort on an unindexed field
- Compound index with the wrong key order
- Large documents sorted fully
- Missing limit()
- Filter not using an index
⚡ Quick fix
db.orders.createIndex({ status: 1, createdAt: -1 })- Add
.limit(n)and projection - Use
.allowDiskUse(true)temporarily
Detailed fix by platform
mongosh
db.orders.find({status:"paid"}).sort({createdAt:-1}).explain("executionStats")showsSORTstage
How to diagnose
- explain — SORT stage in memory?
- Index — Matches filter+sort?
- Limit — Used?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- Atlas: bad auth: Authentication failed MongoServerError: bad auth : Authentication failed. (Atlas user / special characters in password)
- BSONObj size is invalid / exceeds maximum document size (16MB) MongoServerError: BSONObj size: 17825792 (0x1100000) is invalid. Size must be between 0 and 16793600(16MB)
- createIndex failed: unique index with duplicates MongoServerError: Index build failed: E11000 duplicate key error collection: db.users index: email_1 dup key
Most viewed in MongoDB
- Document failed validation MongoDB: MongoServerError: Document failed validation (code 121)
- MongoParseError MongoDB: MongoParseError: Invalid scheme, expected connection string to start with "mongodb://" or "mongodb+srv://"
- bad auth : Authentication failed MongoDB: MongoServerError: bad auth : Authentication failed (code 8000 / 18)
Other ways to find it
Where this error sits
Origin: Data. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 5 Nov 2026