In the mongodb offical documentation, it says:
For example, the collection data has the following index:
{ a: 1, b: 1, c: 1, d: 1 }
The following operations can use the index to get the sort order:
Example
db.data.find( { a: 5 } ).sort( { b: 1, c: 1 } )
db.data.find( { b: 3, a: 4 } ).sort( { c: 1 } )
db.data.find( { a: 5, b: { $lt: 3} } ).sort( { b: 1 } )
I do not understand the second example, why query {b: 5, a: 4}
with sort {c: 1}
can use the index {a: 1, b: 1, c: 1, d: 1}
.
Here is offical documentation.