Pretend that our collection has 1M document
Now if i do aggregation like this:

    $group: {
        _id : "$gender",
        avgAge : { $avg : "$age" }

then how it will prepare the data for me?
Say i have a index on the id but not on the gender so is it gonna read all the 1M documents? if so then how does it scale?

1 Answer 1


Indices can speed up an aggregation when utilized in a $match or a $sort stage at the beginning of a pipeline.

With your example, no index will be used, since you don't use either. So every document will be accessed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.