<!-- llms-explorer concept facts · https://llms-explorer.com/tree/min-max-requiring-hint/ · pack 2026-10-22 · ~728 tokens -->

# min()/max() requiring hint

> Source-anchored research for min()/max() requiring hint. Run status: COMPLETED.

Parent: [MongoDB Explain Plans, Query Planner and Plan Cache](https://llms-explorer.com/tree/mongodb-explain-plans-query-planner-and-plan-cache/) · 2 facets · 7 facts · page: https://llms-explorer.com/tree/min-max-requiring-hint/

## How it works

- MongoDB 4.2 and later requires a hint naming the index when find uses min or max, except when the filter is an equality condition on _id. The MongoDB 4.2 compatibility note says MongoDB 4.0 and earlier could infer the index from the bounds, with possible ambiguity when indexes use the same fields in different key orders. (high confidence) (verified as of 2026-10-14) — [source](https://www.mongodb.com/docs/manual/reference/command/find.md)
- min() specifies an inclusive lower index-key bound and max() specifies an exclusive upper index-key bound. When both methods are used, their bounds must refer to the same index and the max bound must be greater than the min bound. (high confidence) — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.min.md)
- MongoDB min()/max() bounds bypass normal query planning and construct an index scan with the specified bounds. Each method forces the query to use its selected index; with only one bound, the scan is unbounded on the other side and may perform worse. The manual suggests $gte or $lt when those operators fit the query. (high confidence) — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.min.md)
- The PyMongo 4.12 migration guide instructs callers to supply the hint option when find uses min or max; this is a driver-version-specific caller requirement. (medium confidence) — [source](https://pymongo.readthedocs.io/en/4.12.0/migrate-to-pymongo4.html)
- For a MongoDB find cursor, min() or max() requires an explicit hint naming the index, except when the query is an equality match on _id. (high confidence) (verified as of 2026-10-14) — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.min.md)
- MongoDB 4.2 introduced the explicit-hint requirement. In MongoDB 4.0 and earlier, the server could infer the index from min/max bounds when no hint was supplied; that choice could be ambiguous when indexes had the same fields in different sort orders. (medium confidence) (verified as of 2025-04-27) — [source](https://www.alibabacloud.com/help/en/mongodb/user-guide/compatibility-changes-in-mongodb-4-2)

## Problems, failure modes and limitations

- Amazon DocumentDB's compatibility documentation says its cursor.min() and cursor.max() methods require a hint naming the index, require both methods to specify the same fields, cannot be combined with a $natural sort, and are supported only on find. (low confidence) (verified as of 2026-10-20) — [source](https://docs.aws.amazon.com/documentdb/latest/developerguide/mongo-apis.html)
