M201 Chapter 4 Lab 1 Covered Queries

I was looking at the detailed answers to the quiz questions. Please explain why there are three indexes listed, but only two of them are used in the detailed explanation.

Also, there is reference to the hair field, but the index is never used? Is this a misprint or is the bottom index a bogus index and never used.

{ _id: 1 }
{ name: 1, dob: 1 }
{ hair: 1, name: 1 }

Indexes to choose from

db.example.find( { _id : 1117008 }, { _id : 0, name : 1, dob : 1 } )

No, this query would use the _id index, which doesn't match the projected fields.

db.example.find( { name : { $in : [ "Alfred", "Bruce" ] } }, { name : 1, hair : 1 } )

No, this query would use the { name: 1, dob: 1 } index, but it forgets to omit the _id field.

db.example.find( { name : { $in : [ "Bart", "Homer" ] } }, {_id : 0, hair : 1, name : 1} )

No, this query would use the { name: 1, dob: 1 } index, but it is projecting the hair field.

db.example.find( { name : { $in : [ "Bart", "Homer" ] } }, {_id : 0, dob : 1, name : 1} )

Yes, this query would use the { name: 1, dob: 1 } index, which matches the fields in the projection.

Explanations given. Index for { hair : 1, name : 1} is never even referenced. Is this by design?

Thanks

It is simply there to test your knowledge.

The first field of the index is hair:1 so none of the query can use it.

1 Like

I thought that was the case… Just making sure

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