Recall & Review
beginner
What is a query filter in MongoDB?
A query filter is a way to specify conditions to find documents in a collection that match certain criteria.
Click to reveal answer
beginner
How do you filter documents where the field 'age' is exactly 25?
Use { "age": 25 } as the filter to find documents where the 'age' field equals 25.
Click to reveal answer
beginner
What operator do you use to find documents where a field is greater than a value?
Use the $gt operator. For example, { "age": { "$gt": 30 } } finds documents where 'age' is greater than 30.
Click to reveal answer
intermediate
How do you combine multiple conditions in a MongoDB query filter?
By default, listing multiple fields means AND. For OR, use the $or operator with an array of conditions.
Click to reveal answer
intermediate
What does this filter do? { "status": { "$in": ["A", "B"] } }
It finds documents where the 'status' field is either 'A' or 'B'. The $in operator checks if the field matches any value in the array.
Click to reveal answer
Which filter finds documents where 'score' is less than 50?
✗ Incorrect
The $lt operator means 'less than', so { "score": { "$lt": 50 } } finds scores below 50.
How do you find documents where 'age' is 20 AND 'status' is 'active'?
✗ Incorrect
Listing multiple fields in the filter means AND by default, so option B is correct. Option D is also correct as it explicitly uses $and.
What does the $ne operator do?
✗ Incorrect
$ne means 'not equal', so it finds documents where the field is not the given value.
Which filter finds documents where 'category' is either 'books' or 'electronics'?
✗ Incorrect
$in matches any value in the array, so option A finds documents with either category. Option D also finds documents with either category using $or.
How do you find documents where 'price' is between 10 and 20 inclusive?
✗ Incorrect
$gte means 'greater than or equal', $lte means 'less than or equal', so option D finds prices between 10 and 20.
Explain how to write a MongoDB query filter to find documents where a field matches multiple conditions.
Think about combining conditions with AND and OR.
You got /4 concepts.
Describe the purpose and usage of the $in operator in MongoDB query filters.
It helps find documents matching any value from a set.
You got /3 concepts.