Compound index question for sharded collection

There is a collection with a sharding key on the hashed index file_id . In addition, commonly used queries in the business require both id2 and version as query conditions. (it will contain file_id in the query condition as well for shard routing) . For example: find({file_id: 'xxx', id2: 'xxx'}).sort({version: -1}).limit(100)

Given that I already have the hashed index file_id, do I still need to create a compound index (file_id, id2, version) ? Or is it sufficient to create an index on (id2, version) only?

With only file_id index, you can check explain output and see if the query is using that. If not, you may have to create (file_id, id2, version).

This is also related to ESR rule.