In a sharded cluster, but using an unsharded collection, mongoS, given the query:
Will rewrite to:
This can be observed by running the mongoD at logLevel:2 or greater.
As this is targeting a single shard, the query can run as is, mongoD will return everything in correct sorted order.
Two possible answers:
- This is the correct behavior, we will always rewrite (and accept the cost of adding projections). Better for query plan cache filters.
- This isn't correct behavior and when a single shard is targeted the query shouldn't be rewritten. Better for speed and efficiency.