Executor error: Sort exceeded memory limit (find().sort) MongoDB Origin: Data OSI layer 7 · Application Last updated 5 Nov 2026

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.

Exact message you may see 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
Seen on: MongoDB

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

  1. db.orders.createIndex({ status: 1, createdAt: -1 })
  2. Add .limit(n) and projection
  3. Use .allowDiskUse(true) temporarily

Detailed fix by platform

mongosh

  1. db.orders.find({status:"paid"}).sort({createdAt:-1}).explain("executionStats") shows SORT stage

How to diagnose

  1. explain — SORT stage in memory?
  2. Index — Matches filter+sort?
  3. 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:

Where this error sits

Origin: Data. Errors that are often confused with or caused by this one (click to open):

Atlas: bad auth: Authentication failed — MongoServerError: bad auth : Authentication failed. (Atlas user / special characters in password) (MongoDB)Atlas: bad auth: Auth…BSONObj size is invalid / exceeds maximum document size (16MB) — MongoServerError: BSONObj size: 17825792 (0x1100000) is invalid. Size must be between 0 and 16793600(16MB) (MongoDB)BSONObj size is inval…createIndex failed: unique index with duplicates — MongoServerError: Index build failed: E11000 duplicate key error collection: db.users index: email_1 dup key (MongoDB)createIndex failed: u…mongod killed by OOM killer — MongoDB: Out of memory: Killed process (mongod) — WiredTiger cache + queries exhausted RAM (MongoDB)mongod killed by OOM …MongoDB Atlas: connection timed out — IP not whitelisted — MongoServerSelectionError: Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you're trying to access the database from an IP that isn't whitelisted (MongoDB)MongoDB Atlas: connec…MongoServerError: operation exceeded time limit — MongoServerError: operation exceeded time limit (MaxTimeMSExpired) / Query timed out (MongoDB)MongoServerError: ope…Query failed: $or / $in / projection errors (BadValue) — MongoServerError: Unknown modifier / unknown top level operator: $foo / Cannot use $in with a non-array (MongoDB)Query failed: $or / $…Sort/Group exceeded memory limit of 100 MB (allowDiskUse) — MongoServerError: Exceeded memory limit for $group, but didn't allow external sort. Pass allowDiskUse:true to opt in (MongoDB)Sort/Group exceeded m…Executor …

Explore the map of this error Full error map →

🧠 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.