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 $nor operator do in MongoDB?
The $nor operator performs a logical NOR operation on an array of query expressions. It returns documents that fail all the given conditions, meaning none of the conditions are true.
Click to reveal answer
intermediate
How is $nor different from $not in MongoDB?
$nor takes an array of conditions and returns documents where none of the conditions are true. $not negates a single condition. $nor is like combining multiple $not conditions with AND logic.
Click to reveal answer
beginner
Example: What documents does this query return? { $nor: [ { age: { $lt: 30 } }, { status: "A" } ] }
This query returns documents where age is NOT less than 30 AND status is NOT "A". So, only documents that fail both conditions are returned.
Click to reveal answer
intermediate
Can $nor be used with a single condition array? What happens?
Yes, $nor can be used with a single condition inside an array. It returns documents where that single condition is false, effectively negating that condition.
Click to reveal answer
advanced
What happens if the $nor array is empty in a query?
If the $nor array is empty, the query matches all documents because there are no conditions to fail, so none of the conditions are true by default.
Click to reveal answer
What does the $nor operator return in MongoDB?
ADocuments where none of the specified conditions are true
BDocuments where all specified conditions are true
CDocuments where at least one condition is true
DDocuments where exactly one condition is true
✗ Incorrect
$nor returns documents that fail all the given conditions.
Which of these is equivalent to { $nor: [ { age: { $lt: 30 } } ] }?
A{ age: { $lte: 30 } }
B{ age: { $gte: 30 } }
C{ age: { $gt: 30 } }
D{ age: { $lt: 30 } }
✗ Incorrect
$nor with one condition negates it, so it matches documents where age is greater than or equal to 30.
If $nor is given an empty array, what documents are returned?
ANo documents
BOnly documents with null fields
CDocuments with at least one true condition
DAll documents
✗ Incorrect
An empty $nor means no conditions to fail, so all documents match.
How does $nor combine multiple conditions?
AReturns documents where all conditions are true
BReturns documents where any condition is true
CReturns documents where all conditions are false
DReturns documents where exactly one condition is true
✗ Incorrect
$nor returns documents where none of the conditions are true.
Which logical operator is $nor most similar to?
ANOT OR
BAND
COR
DXOR
✗ Incorrect
$nor means NOT (condition1 OR condition2 ...), so it is a NOT OR.
Explain how the $nor operator works in MongoDB queries.
Think about how it combines multiple conditions with NOT and OR.
You got /4 concepts.
Describe a real-life example where you might use $nor in a MongoDB query.
Imagine you want to exclude people younger than 30 or with status 'A'.
You got /3 concepts.
Practice
(1/5)
1. What does the $nor operator do in MongoDB queries?
easy
A. Finds documents where all specified conditions are true
B. Finds documents where at least one condition is true
C. Finds documents where none of the specified conditions are true
D. Finds documents that match exactly one condition
Solution
Step 1: Understand the purpose of $nor
The $nor operator returns documents that do not satisfy any of the given conditions.
Step 2: Compare with other logical operators
Unlike $and or $or, $nor excludes documents matching any condition in its array.
Final Answer:
Finds documents where none of the specified conditions are true -> Option C
Quick Check:
$nor excludes all matching conditions = B [OK]
Hint: Think: no conditions should be true for $nor [OK]
Common Mistakes:
Confusing $nor with $or
Assuming it returns documents matching any condition
Thinking it requires all conditions to be true
2. Which of the following is the correct syntax to use $nor in a MongoDB query to exclude documents where age is 25 or status is "active"?
$nor requires an array of condition objects inside square brackets.
Step 2: Check each option's structure
{ $nor: [ { age: 25 }, { status: "active" } ] } correctly uses an array of conditions. Options B and D use objects incorrectly, and C has invalid array syntax.