发布于 2015-09-14 14:59:18 | 226 次阅读 | 评论: 0 | 来源: 网络整理
Syntax: { $nor: [ { <expression1> }, { <expression2> }, ... { <expressionN> } ] }
$nor performs a logical NOR 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:
db.inventory.find( { $nor: [ { price: 1.99 }, { qty: { $lt: 20 } }, { sale: true } ] } )
This query will select all documents in the inventory collection where:
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:
db.inventory.find( { $nor: [ { price: 1.99 }, { sale: true } ] } )
This query will return all documents that:
Compare that with the following query which uses the $nor operator with the $exists operator:
db.inventory.find( { $nor: [ { price: 1.99 }, { price: { $exists: false } },
{ sale: true }, { sale: { $exists: false } } ] } )
This query will return all documents that: