I am working on the course M201 and am up to lab 3.1.
I ran the following code in my Mongo shell:
exp.find({ "address.state": "NY", stars: { $gt: 3, $lt: 4 } }).sort({ name: 1 }).hint({ "address.state": 1})
And found the following result:
"winningPlan" : {
"stage" : "SORT",
"sortPattern" : {
"name" : 1
},
"inputStage" : {
"stage" : "SORT_KEY_GENERATOR",
"inputStage" : {
"stage" : "FETCH",
"filter" : {
"$and" : [
{
"stars" : {
"$lt" : 4
}
},
{
"stars" : {
"$gt" : 3
}
}
]
},
"inputStage" : {
"stage" : "IXSCAN",
"keyPattern" : {
"address.state" : 1
},
"indexName" : "address.state_1",
"isMultiKey" : false,
"multiKeyPaths" : {
"address.state" : [ ]
},
"isUnique" : false,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 2,
"direction" : "forward",
"indexBounds" : {
"address.state" : [
"[\"NY\", \"NY\"]"
]
}
}
}
}
},
As I understand it, this is the same order of operations as the question asks (IXSCAN -> FETCH -> SORT_KEY_GENERATOR -> SORT).
None of the other hints in the question result in this order. Why is my answer wrong?