The query uses $lt: 10, so it finds documents where price is less than 10.
Step 2: Check each document's price
Only the "Pen" has price 5, which is less than 10. "Notebook" has price 10, which is not less than 10.
Final Answer:
[{ "name": "Pen", "price": 5 }] -> Option C
Quick Check:
Only prices less than 10 included [OK]
Hint: Remember $lt excludes equal values, only strictly less [OK]
Common Mistakes:
Including documents with price equal to 10
Confusing $lt with $lte
Returning empty result by mistake
4. You wrote this query to find documents where score is less than or equal to 50: db.scores.find({ score: { $lt: 50 } }) But you want to include documents where score is exactly 50. What is the error and how to fix it?
medium
A. Use $gt instead of $lt
B. No error, query is correct
C. Add $eq: 50 inside the query
D. Use $lte instead of $lt to include 50
Solution
Step 1: Identify the operator used
The query uses $lt, which excludes values equal to 50.
Step 2: Choose the correct operator to include 50
To include values equal to 50, use $lte (less than or equal).
Final Answer:
Use $lte instead of $lt to include 50 -> Option D
Quick Check:
$lte includes equal values [OK]
Hint: Use $lte to include the boundary value [OK]
Common Mistakes:
Using $lt and expecting equal values included
Using $gt which is wrong direction
Trying to combine $lt and $eq unnecessarily
5. You have a collection orders with documents containing total values. You want to find all orders with total less than or equal to 100 but greater than 50. Which query correctly uses $lt and $lte to achieve this?
hard
A. { total: { $gte: 50, $lt: 100 } }
B. { total: { $gt: 50, $lte: 100 } }
C. { total: { $lt: 100, $lte: 50 } }
D. { total: { $lt: 100, $gt: 50 } }
Solution
Step 1: Understand the range needed
We want totals greater than 50 and less than or equal to 100.
Step 2: Match operators to conditions
$gt: 50 means strictly greater than 50, $lte: 100 means less than or equal to 100.
Step 3: Check query syntax
{ total: { $gt: 50, $lte: 100 } } correctly uses both operators in one object: { total: { $gt: 50, $lte: 100 } }.
Final Answer:
{ total: { $gt: 50, $lte: 100 } } -> Option B
Quick Check:
Use $gt for greater than, $lte for less than or equal [OK]
Hint: Combine $gt and $lte for range queries [OK]
Common Mistakes:
Mixing $lt and $lte incorrectly
Using $gte instead of $gt when strict greater needed