Lab 2.1 Some Issues in Using Index In-Memory Sorting

Intro: While doing the 2.1 lab exam, I found some strange behaviors in Compass’ explain functionality.

Take a look at those queries:

db.people.find({ "address.state": "South Dakota", "first_name": "Jessica" }).sort({ "": -1 })
→ sorted in memory: no

db.people.find({ "address.state": { $lt: "S"}, "first_name": "Jessica" }).sort({ "": -1 })
→ sorted in memory: yes

Can anyone explain why this happens?

We shouldn’t be discussing answers to labs or exams. As you know, once you complete the lab you’ll see the detailed answer for each option.