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 } } ] }The $nor operator returns documents where none of the conditions inside are true. Here, the conditions are price less than 4 or stock equal to 0.
"banana" has price 3 (less than 4) and stock 0, so it matches one of the conditions and is excluded.
"apple" and "orange" do not match either condition, so they are returned.
$nor and $not operators in MongoDB?$nor takes an array of conditions and returns documents where none of those conditions are true.
$not negates a single condition, often used inside a query expression.
They are not interchangeable and have different use cases.
db.collection.find({ $nor: { price: { $lt: 10 }, stock: 0 } })The $nor operator expects an array of conditions. Option D uses an object instead of an array, causing a syntax error.
Options B, C, and D correctly use arrays.
status is "active" nor age is less than 30. Which query is more efficient?Option A uses $and with negated conditions, which is logically equivalent to the $nor in option A but often more efficient and clearer for indexes.
Option A is logically correct but does not use $nor.
Option A misuses $nor with negated conditions, which changes logic.
{"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 } } ] }The $nor operator returns documents where none of the conditions are true.
Here, the conditions are score > 70 and score < 90.
All documents have scores between 75 and 90, so each document matches at least one condition.
Therefore, no document satisfies the $nor condition, resulting in an empty set.