Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What does the $or operator do in MongoDB queries?
The $or operator allows you to specify multiple conditions, and it returns documents that satisfy at least one of those conditions.
Click to reveal answer
beginner
How do you structure a query using $or in MongoDB?
You use $or with an array of condition objects. For example: { $or: [ { age: { $lt: 30 } }, { city: 'New York' } ] } finds documents where age is less than 30 OR city is New York.
Click to reveal answer
intermediate
If a document matches multiple conditions inside $or, how many times does it appear in the result?
The document appears only once in the result, even if it matches multiple $or conditions.
Click to reveal answer
intermediate
Can $or be combined with other operators in the same query?
Yes, $or can be combined with other operators like $and, $not, or direct field queries to build complex filters.
Click to reveal answer
advanced
What happens if you use $or with an empty array in MongoDB?
Using $or with an empty array returns no documents because there are no conditions to satisfy.
Click to reveal answer
What does the MongoDB $or operator require as its value?
AAn array of condition objects
BA single condition object
CA string value
DA number
✗ Incorrect
The $or operator requires an array of condition objects to check if any condition is true.
If a document matches two conditions inside $or, how many times will it appear in the query result?
ANever
BTwice
CDepends on the query
DOnce
✗ Incorrect
Documents appear only once in the result even if they match multiple $or conditions.
Which of the following is a valid $or query in MongoDB?
The $or operator requires an array of condition objects inside square brackets.
Step 2: Validate each option's syntax
{ $or: [ { age: { $lt: 20 } }, { city: "NY" } ] } correctly uses an array with two objects. Options A, B, and C use incorrect brackets or missing array syntax.
D. $or requires an array of conditions, not a single object.
Solution
Step 1: Analyze the $or syntax
$or expects an array of condition objects, but here it is given a single object.
Step 2: Identify the error cause
Because the value is not an array, MongoDB throws a syntax error.
Final Answer:
$or requires an array of conditions, not a single object. -> Option D
Quick Check:
$or needs array syntax [OK]
Hint: Always wrap $or conditions in square brackets [OK]
Common Mistakes:
Using object instead of array for $or conditions
Misplacing operators inside $or
Ignoring syntax errors from missing brackets
5.
You want to find documents in a products collection where the category is either "electronics" or the price is less than 100. Which query correctly uses $or to achieve this?