$nor
On this page本页内容
Definition定义
$nor
-
$nor
performs a logicalNOR
operation on an array of one or more query expression and selects the documents that fail all the query expressions in the array.$nor
对一个或多个查询表达式的数组执行逻辑NOR
运算,并选择数组中所有查询表达式都失败的文档。The$nor
has the following syntax:$nor
具有以下语法:{ $nor: [ { <expression1> }, { <expression2> }, ... { <expressionN> } ] }
Examples实例
$nor
Query with Two Expressions带有两个表达式的$nor
查询
$nor
Query with Two ExpressionsConsider the following query which uses only the 考虑以下仅使用$nor
operator:$nor
运算符的查询:
db.inventory.find( { $nor: [ { price: 1.99 }, { sale: true } ] } )
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
or1.99
的price
字段和值不等于true
的sale
字段,或contain the包含值不等于price
field whose value is not equal to1.99
but do not contain thesale
field or1.99
的price
字段,但不包含sale
字段,或do not contain the不包含price
field but contain thesale
field whose value is not equal totrue
orprice
字段,但包含值不等于true
的sale
字段,或do not contain the不包含price
field and do not contain thesale
fieldprice
字段和sale
字段
$nor
and Additional Comparisons以及其他比较
Consider the following query:请考虑以下查询:
db.inventory.find( { $nor: [ { price: 1.99 }, { qty: { $lt: 20 } }, { sale: true } ] } )
This query will select all documents in the 此查询将选择inventory
collection where:inventory
集合中的所有文档,其中:
theprice
field value does not equal1.99
andprice
字段值不等于1.99
,并且theqty
field value is not less than20
andqty
字段值不小于20
,并且thesale
field value is not equal totrue
sale
字段值不等于true
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.$nor
表达式中字段的文档时,$nor
运算符与$exists
运算符一起使用的情况除外。
$nor
and 和$exists
Compare that with the following query which uses the 将其与以下使用$nor
operator with the $exists
operator:$nor
运算符和$exists
运算符的查询进行比较:
db.inventory.find( { $nor: [ { price: 1.99 }, { price: { $exists: false } },
{ sale: true }, { sale: { $exists: false } } ] } )
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
1.99
的price
字段和值不等于true
的sale
字段