$nor¶
-
$nor¶ Syntax:
{ $nor: [ { <expression1> }, { <expression2> }, ... { <expressionN> } ] }$norperforms a logicalNORoperation 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
inventorycollection where:- the
pricefield value does not equal1.99and - the
qtyfield value is not less than20and - the
salefield 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
$norexpression is when the$noroperator is used with the$existsoperator.Consider the following query which uses only the
$noroperator:This query will return all documents that:
- contain the
pricefield whose value is not equal to1.99and contain thesalefield whose value is not equal totrueor - contain the
pricefield whose value is not equal to1.99but do not contain thesalefield or - do not contain the
pricefield but contain thesalefield whose value is not equal totrueor - do not contain the
pricefield and do not contain thesalefield
Compare that with the following query which uses the
$noroperator with the$existsoperator:This query will return all documents that:
- contain the
pricefield whose value is not equal to1.99and contain thesalefield whose value is not equal totrue
- the