Recall & Review
beginner
What does the
$and operator do in MongoDB queries?The
$and operator combines multiple conditions and returns documents that satisfy all of them.Click to reveal answer
beginner
How do you use comparison operators like
$gt and $lt in MongoDB?Comparison operators like
$gt (greater than) and $lt (less than) are used inside query objects to filter documents based on field values.Click to reveal answer
intermediate
Explain how to combine
$or with comparison operators in a MongoDB query.You use
$or to specify multiple alternative conditions. Each condition can use comparison operators. The query returns documents matching any one of the conditions.Click to reveal answer
beginner
What is the difference between
$and and $or in MongoDB queries?$and requires all conditions to be true for a document to match, while $or requires at least one condition to be true.Click to reveal answer
beginner
How would you write a MongoDB query to find documents where age is greater than 25 and status is 'active'?
Use
{ $and: [ { age: { $gt: 25 } }, { status: 'active' } ] }. This finds documents where both conditions are true.Click to reveal answer
Which operator in MongoDB returns documents that satisfy all given conditions?
✗ Incorrect
The $and operator requires all conditions to be true for a document to match.
How do you check if a field 'score' is less than 50 in MongoDB?
✗ Incorrect
The $lt operator means 'less than', so { score: { $lt: 50 } } finds documents with score less than 50.
What does the following query do? { $or: [ { age: { $gt: 30 } }, { status: 'active' } ] }
✗ Incorrect
The $or operator returns documents matching any one of the conditions.
Which operator would you use to combine conditions that all must be true?
✗ Incorrect
$and combines conditions that all must be true.
How do you write a query to find documents where 'price' is between 10 and 20 inclusive?
✗ Incorrect
$gte means greater than or equal, $lte means less than or equal, so this finds prices between 10 and 20 inclusive.
Describe how to combine logical operators with comparison operators in a MongoDB query.
Think about how you can ask for multiple conditions at once.
You got /4 concepts.
Explain the difference between $and and $or operators in MongoDB with examples.
Think about 'all' versus 'any' conditions.
You got /4 concepts.