M210 Lab 1 answers expained

I cannot get a picture to copy because I am using an Apple MacBook dual Booted for windows 10 and I am in the windows boot, so I am going to type the entire thing.

In lab one it asks which query would use the index for both querying and sorting.

I got the middle two, but I would like some clairificaiton on this one.

In compass I went to the explain plan and I typed the following in.

Filter: { “first_name”: “Jessica”, “address.state” : {$lt: “S”}}
Sort: { “address.city” : 1}

the above query typed into the compass explain plan should be the same as:

db.people.find({ "first_name": "Jessica", "address.state": { $lt: "S"} }).sort({ "address.state": 1 })

I ran this query and the result says Sorted in Memory: yes.

Right below the memory: yes, it says that the query used the following index… Does that mean it used it for both the match and sort stage?

It was my understanding that if you sort in memory, you will not have used an index for the sort. Am I wrong?

In one case you sourt address.city and in the other you sort address.state so explain plan should not be the same.

Thanks Steevej… I looked at your response on my phone and went back and reentered the queries. I mistyped.

I now know that order matters when it comes to fields and indexes… LOL
Thanks for your help. (I’m gonna private email you…) Got some more questions for you.

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