Order MongoDB compound-index fields as Equality → Sort → Range so the query planner keeps a tight IXSCAN and avoids in-memory sorts.
Order fields as Equality → Sort → Range.
=sort()<, >, between, or $in over a large setMongoDB consumes the index left-to-right. Equality fields narrow the scan to a contiguous key range; sort fields let the engine return results without an in-memory sort; range fields expand the scan and must come last — placing them earlier forces a wider scan and may break sort usage.
db.<coll>.find(...).explain("executionStats"): want IXSCAN and , with no stage.nReturned ≈ totalDocsExaminedSORT@CompoundIndexes({
@CompoundIndex(name = "tenant_service_time",
def = "{tenantId:1, serviceId:1, startTime:-1, duration:1}")
// E: tenantId, serviceId S: startTime (desc) R: duration
})
$in with a small list behaves like equality; large $in lists are range-like.hint() can invalidate this reasoning — always re-check with explain().