Hint: Look for documents matching the filter condition carefully [OK]
Common Mistakes:
Including documents with price equal to 4
Selecting documents with price less than 4
Misunderstanding $gt operator
4. What is wrong with this MongoDB query to find users older than 25? db.users.find({ age: > 25 })
medium
A. The query is missing a closing parenthesis.
B. The comparison operator > is used incorrectly inside the query object.
C. The find() method cannot filter by age.
D. The collection name should be in quotes.
Solution
Step 1: Analyze the query syntax
The query uses age: > 25, which is invalid syntax in MongoDB.
Step 2: Identify correct operator usage
MongoDB requires operators like $gt inside an object: { age: { $gt: 25 } }.
Final Answer:
The comparison operator > is used incorrectly inside the query object. -> Option B
Quick Check:
Use $gt for greater than in queries [OK]
Hint: Use $gt, not >, inside query objects [OK]
Common Mistakes:
Using > directly instead of $gt
Putting collection name in quotes unnecessarily
Assuming find() can't filter by fields
5. You have a collection orders with documents containing status and total. How would you write a query to find all orders with status "shipped" and total greater than 100?
hard
A. db.orders.find({ status: "shipped", total: { $gt: 100 } })