0
0
MongoDBquery~20 mins

$nor operator behavior in MongoDB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
MongoDB $nor Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What documents are returned by this $nor query?
Given a collection products with documents:
{"item": "apple", "price": 5, "stock": 10}
{"item": "banana", "price": 3, "stock": 0}
{"item": "orange", "price": 7, "stock": 5}

What documents will be returned by this query?
{ "$nor": [ { "price": { "$lt": 4 } }, { "stock": { "$eq": 0 } } ] }
A[{"item": "orange", "price": 7, "stock": 5}]
B[{"item": "banana", "price": 3, "stock": 0}]
C[{"item": "apple", "price": 5, "stock": 10}, {"item": "orange", "price": 7, "stock": 5}]
D[{"item": "apple", "price": 5, "stock": 10}]
Attempts:
2 left
💡 Hint
Remember $nor returns documents where none of the conditions inside it are true.
🧠 Conceptual
intermediate
1:30remaining
How does $nor differ from $not in MongoDB?
Which statement correctly describes the difference between $nor and $not operators in MongoDB?
A$nor takes an array of conditions and returns documents where none are true; $not negates a single condition.
B$nor only works with numeric fields; $not works with string fields.
C$nor and $not are interchangeable and behave the same way.
D$nor negates a single condition; $not takes an array of conditions and returns documents where none are true.
Attempts:
2 left
💡 Hint
Think about how many conditions each operator accepts and what they negate.
📝 Syntax
advanced
1:30remaining
Identify the syntax error in this $nor query
Which option contains a syntax error in the $nor query?
MongoDB
db.collection.find({ $nor: { price: { $lt: 10 }, stock: 0 } })
Adb.collection.find({ $nor: [ { price: { $lt: 10 } }, { stock: { $ne: 0 } } ] })
Bdb.collection.find({ $nor: [ { price: { $lt: 10 } }, { stock: 0 } ] })
Cdb.collection.find({ $nor: [ { price: { $lt: 10 } }, { stock: { $eq: 0 } } ] })
Ddb.collection.find({ $nor: { price: { $lt: 10 }, stock: 0 } })
Attempts:
2 left
💡 Hint
$nor requires an array of conditions, not an object.
optimization
advanced
2:00remaining
Optimizing a $nor query for performance
You want to find documents where neither status is "active" nor age is less than 30. Which query is more efficient?
Adb.collection.find({ $and: [ { status: { $ne: "active" } }, { age: { $gte: 30 } } ] })
Bdb.collection.find({ status: { $ne: "active" }, age: { $gte: 30 } })
Cdb.collection.find({ $nor: [ { status: { $ne: "active" } }, { age: { $gte: 30 } } ] })
Ddb.collection.find({ $nor: [ { status: "active" }, { age: { $lt: 30 } } ] })
Attempts:
2 left
💡 Hint
Think about how $nor negates conditions and how $and with negations can be clearer.
🔧 Debug
expert
2:30remaining
Why does this $nor query return no documents?
Given documents:
{"name": "Alice", "score": 85}
{"name": "Bob", "score": 90}
{"name": "Carol", "score": 75}

Why does this query return an empty result?
{ "$nor": [ { "score": { "$gt": 70 } }, { "score": { "$lt": 90 } } ] }
ABecause $nor requires at least three conditions to work properly.
BBecause every document matches at least one condition inside $nor, so none are returned.
CBecause the query syntax is invalid and causes an error.
DBecause $nor only works with string fields, not numeric fields like score.
Attempts:
2 left
💡 Hint
Check if any document can avoid matching both conditions inside $nor.