0
0
MongoDBquery~5 mins

Query filter syntax in MongoDB - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
A{ "score": { "$eq": 50 } }
B{ "score": { "$gt": 50 } }
C{ "score": 50 }
D{ "score": { "$lt": 50 } }
How do you find documents where 'age' is 20 AND 'status' is 'active'?
A{ "$or": [ { "age": 20 }, { "status": "active" } ] }
B{ "age": 20, "status": "active" }
C{ "age": { "$eq": 20 }, "status": { "$eq": "active" } }
D{ "$and": [ { "age": 20 }, { "status": "active" } ] }
What does the $ne operator do?
AMatches values greater than the specified value
BMatches values equal to the specified value
CMatches values not equal to the specified value
DMatches values less than the specified value
Which filter finds documents where 'category' is either 'books' or 'electronics'?
A{ "category": { "$in": ["books", "electronics"] } }
B{ "category": { "$all": ["books", "electronics"] } }
C{ "category": "books" }
D{ "$or": [ { "category": "books" }, { "category": "electronics" } ] }
How do you find documents where 'price' is between 10 and 20 inclusive?
A{ "price": { "$gte": 10, "$lte": 20 } }
B{ "price": { "$gt": 10, "$lt": 20 } }
C{ "price": { "$in": [10, 20] } }
D{ "price": { "$ne": 10, "$ne": 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.