0

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

db.users.aggregate({
 $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?

asked May 7, 2015 at 14:55

1 Answer 1

0

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.

answered May 7, 2015 at 20:31

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.