# MongoServerError: Executor error during find command :: caused by :: Sort exceeded memory limit of 104857600 bytes, but did not opt in to external sorting

**Code:** `Executor error: Sort exceeded memory limit (find().sort)` · **Category:** MongoDB · **Seen on:** MongoDB

A `find().sort()` without a supporting index had to sort too much data in memory.

## 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?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/mongodb/query-planner-executor-error-sort-exceeded)
