Ensuring that the $sort stage uses indexes

I have created the above query. There is an index on A, but before the $sort stage of the aggregation pipeline, data is modified. However, the field that is modified is not A.

How it could use the index on A to perform the sort.

Will it?

Hello @Big_Cat_Public_Safety_Act,

The $sort operator can take advantage of an index if it’s used in the first stage of a pipeline or if it’s only preceded by a $match stage.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.