The ESR rule guides MongoDB compound-index design: place equality fields first, sort fields next, and range fields last. This sequence narrows results, supports ordering, and applies range filtering efficiently. section 7.2.2
Apply the rule to query requirements:
- Put exact-match fields at the beginning because equality searches reduce the documents MongoDB reviews. section 7.2.2
- Follow equality fields with fields used to sort, then place range-filter fields such as $gte. section 7.2.2
- Remove a standalone prefix index when an equivalent compound index already supports its queries; compound indexes allow up to 32 fields. section 7.2.2
Movie query
For movies from 1914 with an IMDb rating of at least 7, sorted by title, create { year: 1, title: 1, "imdb.rating": 1 }. The explain plan uses IXSCAN and FETCH rather than a collection scan. section 7.2.2
