Recall & Review
beginner
What does combining comparison operators in MongoDB allow you to do?
It allows you to filter documents by applying multiple conditions on the same field, such as finding values greater than one number and less than another.
Click to reveal answer
beginner
How do you combine comparison operators like $gt and $lt in a MongoDB query?
You put them inside the same field object, for example: { age: { $gt: 20, $lt: 30 } } to find ages greater than 20 and less than 30.
Click to reveal answer
intermediate
What is the difference between using $and operator and combining comparison operators inside one field in MongoDB?
$and combines multiple conditions that can be on different fields, while combining comparison operators inside one field applies multiple conditions on the same field.
Click to reveal answer
beginner
Example: How to find documents where price is between 10 and 50 in MongoDB?
Use: { price: { $gte: 10, $lte: 50 } } which means price greater than or equal to 10 and less than or equal to 50.
Click to reveal answer
intermediate
Can you combine $ne (not equal) with other comparison operators on the same field in MongoDB?
Yes, for example: { score: { $ne: 100, $gt: 50 } } finds scores not equal to 100 and greater than 50.
Click to reveal answer
How do you write a MongoDB query to find documents where age is greater than 18 and less than 30?
✗ Incorrect
Combining $gt and $lt inside the same field object is the correct syntax to find age greater than 18 and less than 30.
Which operator is used to combine multiple conditions on different fields in MongoDB?
✗ Incorrect
$and is used to combine multiple conditions on different fields.
What does this query do? { price: { $gte: 100, $lte: 200 } }
✗ Incorrect
$gte and $lte combined find values between 100 and 200 including those numbers.
Is this query valid? { score: { $ne: 50, $gt: 30 } }
✗ Incorrect
You can combine $ne with other comparison operators on the same field.
What is the difference between { age: { $gt: 20, $lt: 30 } } and { $and: [ { age: { $gt: 20 } }, { age: { $lt: 30 } } ] }?
✗ Incorrect
Both queries find ages greater than 20 and less than 30; they are equivalent.
Explain how to combine multiple comparison operators on the same field in a MongoDB query.
Think about putting conditions inside one object for the field.
You got /3 concepts.
Describe the difference between using $and operator and combining comparison operators inside one field in MongoDB.
Consider when you want to filter by one field versus multiple fields.
You got /3 concepts.