$nor¶
-
$nor
¶ Syntax:
{ $nor: [ { <expression1> }, { <expression2> }, ... { <expressionN> } ] }
$nor
performs a logicalNOR
operation on an array of two or more<expressions>
and selects the documents that fail all the<expressions>
in the array.Consider the following example:
This query will select all documents in the
inventory
collection where:- the
price
field value does not equal1.99
and - the
qty
field value is not less than20
and - the
sale
field value is not equal totrue
including those documents that do not contain these field(s).
The exception in returning documents that do not contain the field in the
$nor
expression is when the$nor
operator is used with the$exists
operator.Consider the following query which uses only the
$nor
operator:This query will return all documents that:
- contain the
price
field whose value is not equal to1.99
and contain thesale
field whose value is not equal totrue
or - contain the
price
field whose value is not equal to1.99
but do not contain thesale
field or - do not contain the
price
field but contain thesale
field whose value is not equal totrue
or - do not contain the
price
field and do not contain thesale
field
Compare that with the following query which uses the
$nor
operator with the$exists
operator:This query will return all documents that:
- contain the
price
field whose value is not equal to1.99
and contain thesale
field whose value is not equal totrue
- the