Which Aggregate operation use Indexscan?

Does aggregate use IXSCAN? which operation of aggregate use IXSCAN?

The stages $match, $sort and $project (may $group) may perform IXSCAN when an appropriate index exists. See:

I know that $match and $sort only in first stage use IXSCAN . Am I correct?
IF not , can you give example where $match and $sort use IXSCAN ?

I also request you to give me example where $group / $project , where they use use IXSCAN

Sorry, I do not have any example at hand that does not use $match or $sort.

any example of $group or $project that uses index

The above is the same question as the previous one

And my answer is the same:

I could try to come up with something but it might involve too much time. I prefer to help on more specific issues like Why COLLSCAN and IXSCAN take same to search data? - #3 by Prof_Monika_Shah for which we are still awaiting some information.

1 Like

Hi @Prof_Monika_Shah,

Please refer to the MongoDB server manual for more information on Pipeline Operators and Indexes and Aggregation Pipeline Optimisation.

Stages that can use an index (and will be included in aggregation explain output) currently include $match, $sort, $group, and $geonear) .

The $lookup and $graphLookup stages can also use indexes on from collections but the aggregation explain output (as at MongoDB 5.0) only describes indexes on the collection the aggregate command is invoked on. There’s an open feature request to improve explain output for $lookup: SERVER-22622.

Stages that transform data (like $project) rely on index usage in previous stages that fetch data (for example, an initial $match + $sort).