0
votes

Can MongoDB use an index defined in ascending order (with {x:1}) for sorting in descending order sort({x:-1})?

My guess is yes since it is possible to reverse the result set.

explain() tells me that it actually used it ("cursor" : "BtreeCursor x_1 reverse") but I am still not sure.

1

1 Answers

0
votes

Yes it can but, to throw a spanner in the works, it cannot use a compound index in reverse order.

So lets say you have defined:

{x:1,d:1}

You cannot use this index to sort like:

{x:1,d:-1}