<!-- llms-explorer concept facts · https://llms-explorer.com/tree/sort-direction-and-compound-index-prefix-rules/ · pack 2026-10-20 · ~949 tokens -->

# Sort direction and compound index prefix rules

> Source-anchored research for Sort direction and compound index prefix rules. Run status: COMPLETED.

Parent: [MongoDB Compound Index Design: ESR, Selectivity, Covering and Multikey Bounds](https://llms-explorer.com/tree/mongodb-compound-index-design-esr-selectivity-covering-and-multikey-bounds/) · 3 facets · 8 facts · page: https://llms-explorer.com/tree/sort-direction-and-compound-index-prefix-rules/

## How it works

- MongoDB Jira issue SERVER-100910 records a reverse-scan planning defect for bounded sorts on compound time-series indexes and lists the fix version as 9.0.0-rc0. Check the deployed server version and explain() plan when applying general reverse-sort rules to this special index type. (low confidence) (verified as of 2026-10-20) — [source](https://jira.mongodb.org/browse/SERVER-100910)
- MongoDB can provide an index-backed sort on a compound index when sort keys appear in the same relative order as index keys. A leading subset of index keys can satisfy a sort, but reordering the sort fields does not match that index order. (high confidence) — [source](https://www.mongodb.com/docs/manual/tutorial/sort-results-with-indexes/)

## Problems, failure modes and limitations

- Compound indexes are ordered left to right. Their leading key or keys form the efficient search prefixes; a query that omits the first key cannot use later keys as an equivalent prefix. When a query matches a leading prefix and also filters a later indexed field, MongoDB can scan the prefix and filter that later field, but this can examine more keys than an index whose key pattern matches the query fields directly. (high confidence) — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-compound.md)
- MongoDB can use a compound index to provide a sort when requested sort keys follow their order in the index. A sort on a later, non-prefix subset requires equality predicates on every index key before the first sort key. Without those equalities, the index cannot efficiently provide that sort and the plan may need an in-memory SORT stage. (high confidence) — [source](https://www.mongodb.com/docs/manual/tutorial/sort-results-with-indexes/)

## Facts and statements

- For a multi-field sort, the sort key order must match the index key order, and the requested directions must either match the index directions or reverse every direction. For example, index {a: 1, b: -1} supports sorts {a: 1, b: -1} and {a: -1, b: 1}, but not {a: 1, b: 1} or {a: -1, b: -1}. (high confidence) — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-compound/sort-order.md)
- A single-field index can satisfy ascending or descending sorts by scanning forward or backward, so its declared direction does not constrain the requested sort direction. Direction patterns matter for compound sorts with multiple keys. (high confidence) — [source](https://www.mongodb.com/docs/manual/tutorial/sort-results-with-indexes/)
- An index pattern that can provide a sort does not guarantee the planner will choose that index; competing indexes and the full query shape can change the winning plan. Check explain() to see whether the plan has an index-backed order or a SORT stage. (medium confidence) — [source](https://www.percona.com/blog/mongodb-index-usage-and-mongodb-explain-part-1/)
- For a multi-field sort, every requested direction must match the corresponding compound-index direction or all requested directions must be reversed together; reversing only some fields does not match the index pattern. A single-field index supports ascending or descending sort by traversing the index in either direction. (high confidence) — [source](https://www.mongodb.com/docs/manual/tutorial/sort-results-with-indexes/)
