I just did the practice exam and this was one of the answers:
All answer choices are correct!
Consider just the first choice. Any document that could match "manufacturer is Matteo AND name is Barbara AND date is 2018-07-02 would have to match date is 2018-07-02 AND, name is Barbara, and manufacturer is Matteo .
Because of this fact, the optimizer is able to rearrange the the search terms, using the existing index for each query.
To learn more, visit the following MongoDB Documentation page: https://docs.mongodb.com/manual/core/index-compound/#prefixes
This makes total sense to me, but I don’t really see it laid out in the prefix docs and I feel in the course it was explicitly outlined that the index prefix had to match in a specific order.
So based on the above indexes of
"manufacturer" : 1,
"name" : 1,
"date" : -1
}
Can the optimizer only reorder a full compound index query like:
db.toys.find( { manufacturer : "Matteo", name : "Barbara", date : "2018-07-02" } )
or can it reorder a partially used compound index, say I just searched for:
db.toys.find( { name : "Barbara", manufacturer : "Matteo" } )