On this page
$nor
在本页面
{ $nor: [ { <expression1> }, { <expression2> }, ... { <expressionN> } ] }
Examples
$ nor 带有两个表达式的查询
考虑以下仅使用$nor运算符的查询:
db.inventory.find( { $nor: [ { price: 1.99 }, { sale: true } ] } )
该查询将返回以下所有文档:
包含
price
字段,其值不等于1.99
,并包含sale
字段,其值不等于true
或包含
price
字段,其值不等于1.99
但是不*包含sale
字段 或不包含
price
字段但包含sale
字段,其值不等于true
或不包含
price
字段和不*包含sale
字段
$ nor 和其他比较
考虑以下查询:
db.inventory.find( { $nor: [ { price: 1.99 }, { qty: { $lt: 20 } }, { sale: true } ] } )
此查询将选择inventory
集合中的所有文档,其中:
price
字段值不等于1.99
和qty
字段的值*不小于20
并且sale
字段的值不等于true
包括那些不包含这些字段的文档。
当$nor运算符与$exists运算符一起使用时,返回不包含$nor表达式中的字段的文档的 exception。
$ nor 和$ exists
将其与使用$nor运算符和$exists运算符的以下查询进行比较:
db.inventory.find( { $nor: [ { price: 1.99 }, { price: { $exists: false } },
{ sale: true }, { sale: { $exists: false } } ] } )
该查询将返回以下所有文档:
- 包含值不等于
1.99
的price
字段,以及值不等于true
的sale
字段