The query uses $gt: 10, so it selects documents where price is strictly greater than 10.
Step 2: Check each document's price
"Pen" has price 5 (not > 10), "Notebook" has price 10 (not > 10), "Backpack" has price 20 (greater than 10).
Final Answer:
[{ "name": "Backpack", "price": 20 }] -> Option D
Quick Check:
Only price > 10 matches [OK]
Hint: Remember $gt excludes equal values [OK]
Common Mistakes:
Including documents with price equal to 10
Confusing $gt with $gte
Selecting documents with price less than 10
4. You wrote the query db.users.find({ age: { $gte: 21 } }) but it returns no results even though some users are 21 or older. What is the likely problem?
medium
A. You should use $gt instead of $gte.
B. The field name age is misspelled in the documents.
C. The query syntax is incorrect; $gte cannot be used here.
D. MongoDB does not support $gte operator.
Solution
Step 1: Check the query syntax
The syntax { age: { $gte: 21 } } is correct and supported by MongoDB.
Step 2: Consider data issues
If no results appear, likely the field age is misspelled or missing in documents, so no matches occur.
Final Answer:
The field name age is misspelled in the documents. -> Option B
Quick Check:
Field name mismatch causes no results [OK]
Hint: Check field names carefully if no results [OK]
Common Mistakes:
Assuming $gte is unsupported
Switching $gte to $gt unnecessarily
Ignoring possible typos in field names
5. You want to find all orders with a total amount greater than or equal to 100 but less than 200. Which MongoDB query correctly uses $gte and $gt to achieve this?
hard
A. { total: { $gte: 100, $lt: 200 } }
B. { total: { $gt: 100, $gte: 200 } }
C. { total: { $gte: 100, $gt: 200 } }
D. { total: { $gte: 100, $gt: 199 } }
Solution
Step 1: Understand the range conditions
You want totals >= 100 and < 200, so use $gte: 100 and $lt: 200 (less than 200).
Step 2: Check each option's operators
{ total: { $gte: 100, $lt: 200 } } correctly uses $gte: 100 and $lt: 200. Other options misuse operators or values.
Final Answer:
{ total: { $gte: 100, $lt: 200 } } -> Option A
Quick Check:
Use $gte for lower bound, $lt for upper bound [OK]
Hint: Use $gte for start, $lt for end of range [OK]