What the query planner does
coreintermediateBefore running a query, MongoDB's query planner considers every index that could help, runs the plausible candidates for a short trial, and picks whichever returned the most results for the least work. That choice is then cached and reused for future queries of the same shape.
Think of it as
The planner behaves like someone trying several routes on a short test drive before committing to one for a regular commute — it does not reason abstractly about which route "should" be fastest, it tries the realistic candidates briefly and picks the one that performed best. This is why the winning plan can be understood but is not something you configure directly — it is discovered.
What we're doing: Show two candidate plans (two different indexes) being evaluated, and the trial-based reasoning behind the winner.
- 1
- Both indexes could technically serve this query, which is exactly why the planner needs to choose between real candidates rather than there being one obvious answer.
- 5
- The compound index avoids an extra in-memory sort step, so it produces the requested results with less work — that is what the trial period is measuring, not an abstract judgment about index design.
Why this works: Understanding that the planner discovers the winner empirically, rather than reasoning about it from index definitions alone, explains why adding or dropping an index can change a query's plan even when the query itself never changes.
Assuming the "obviously better" index is always the one MongoDB picks
Wrong
Better
What you see: A query performs worse than expected despite a "better" index existing, because the plan cache is still serving an older winner from before conditions changed.
Why: The planner's choice is based on a real trial and then cached — it is not re-evaluated on every single query, so a plan that made sense earlier can persist past a point where a different index would now do less work, until the cache entry is invalidated.
- candidate plans — one per usable index
- trial run — most results, least work
- winning plan — cached for reuse
Remember: The planner runs plausible candidate plans in a short trial, picks the one returning the most results for the least work, and caches that winner for future queries of the same shape. explain() always bypasses the cache.
See also: collscan vs ixscan · explain basics

