对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

$nor(查询谓词操作符)

$nor

$nor performs a logical NOR operation on an array of one or more query predicates and selects the documents that fail all the query predicates in the array. The $nor has the following syntax:

{ $nor: [ { <expression1> }, { <expression2> }, ... { <expressionN> } ] }

Consider the following query which uses only the $nor operator:

db.inventory.find( { $nor: [ { price: 1.99 }, { sale: true } ] } )

该查询将返回满足以下条件的所有文档:

  • 包含值不 等于 1.99 的 price 字段,并包含值不 为 true 的 sale 字段或

  • 包含值不等于 1.99 的 price 字段,但不包含 sale 字段,或者

  • 不包含 price 字段,但包含值不等于 true 的 sale字段,或者

  • 不包含 price 字段,也不包含 sale 字段

考虑以下查询:

db.inventory.find( { $nor: [ { price: 1.99 }, { qty: { $lt: 20 } }, { sale: true } ] } )

该查询选择 inventory 集合中满足如下条件的所有文档:

  • price 字段值不等于 1.99 并且

  • qty 字段值不小于 20 并且

  • sale 字段值不等于 true

包括那些不包含这些字段的文档。

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.

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 } } ] } )

该查询将返回满足以下条件的所有文档:

  • 包含值不等于 1.99 的 price 字段,并包含值不为 true 的 sale 字段
给本页内容打分

在此页面上