M201 lab 3.1 (Explain output)

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?

Hello @Spirit_Dragon welcome to the community!
We are happy to help, however this is a University question which has a dedicated forum for each class. Please follow this link to reach the M201 University Forum.
Concerning your question: you are on a good path, just rethink your hint with the equality, sort, range rule in mind.

Hope this hint helps :wink:
Michael

3 Likes