Lab 2.1 : first answer IS correct

Hi,
accroding to the course material the first query :
db.people.find({ “first_name”: { $gt: “J” } }).sort({ “address.city”: -1 })
should not use the index since first_name is not with an equality opertaor. However, when I explain plan on a local mongo installation, it says it is using an index scan.

Can you please explain?

“winningPlan” : {
“stage” : “SORT”,
“sortPattern” : {
“address.city” : -1
},
“inputStage” : {
“stage” : “SORT_KEY_GENERATOR”,
“inputStage” : {
“stage” : “FETCH”,
“inputStage” : {
“stage” : “IXSCAN”,
“keyPattern” : {
“first_name” : 1,
“address.state” : -1,
“address.city” : -1,
“ssn” : 1
},
“indexName” : “first_name_1_address.state_-1_address.city_-1_ssn_1”,
“isMultiKey” : false,
“multiKeyPaths” : {
“first_name” : ,
“address.state” : ,
“address.city” : ,
“ssn” :
},
“isUnique” : false,
“isSparse” : false,
“isPartial” : false,
“indexVersion” : 2,
“direction” : “forward”,
“indexBounds” : {
“first_name” : [
“(“J”, {})”
],
“address.state” : [
“[MaxKey, MinKey]”
],
“address.city” : [
“[MaxKey, MinKey]”
],
“ssn” : [
“[MinKey, MaxKey]”
]
}
}
}
}

I have the same concern, please explain!

I am running a local mongo 4.0.6 instance for this course. When I tried running the query in the question - the explain() output shows that the index is used for both find() and sort(), even though I am not using equality in the Find clause.
In the lab, the expected answer is different from what actually happens on my mongo (this is how I understand the output of explain() that I attached to the question).
Either I do not understand the explain() output or the expected answer is different from the actual behavior.

@Shay_54085

You have misread or misunderstood the explain() output. Read the documentation here which says

If MongoDB can use an index scan to obtain the requested sort order, the result will **not** include a 'SORT' stage. Otherwise, if MongoDB cannot use the index to sort, the 'explain' result will include a 'SORT' stage.

Remember that the question is to indicate the queries that can use the index for both selection and sorting.