# $nor

在本页面

* [例子](#examples)

**$nor**

`$nor`对包含一个或多个查询表达式的数组执行逻辑`nor`操作，并选择数组中所有查询表达式失败的文档。`$nor`有以下语法:

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

> **也可以看看**
>
> [`find()`](/can-kao/yun-suan-fu/query-and-projection-operators/logical-query-operators/nor.md), [`update()`](/can-kao/yun-suan-fu/query-and-projection-operators/logical-query-operators/nor.md), [`$or`](/can-kao/yun-suan-fu/query-and-projection-operators/logical-query-operators/nor.md), [`$set`](/can-kao/yun-suan-fu/query-and-projection-operators/logical-query-operators/nor.md), and [`$exists`](/can-kao/yun-suan-fu/query-and-projection-operators/logical-query-operators/nor.md).

## 例子

### `$nor`查询有两种表述

考虑以下仅使用`$nor`操作符的查询:

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

此查询将返回以下所有文档:

* 包含值不等于`1.99`的`price`字段和不等于`true`或的`sale`字段
* 包含`price`字段，其值不等于`1.99`，但不包含`sale`字段
* 不包含`price`字段，但`sale`包含值不等于`true`
* 不包含`price`字段和不包含`sale`字段

### `$nor`和另外的比较

考虑以下查询:

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

此查询将选择库存集合中的所有文档，其中:

* `price`字段值不等于`1.99`和
* `qty`字段值不小于`20`和
* `sales`字段的值不等于`true`

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

返回不包含`$nor`表达式中字段的文档的例外情况是，`$nor`操作符与`$exists`操作符一起使用。

### `$nor`和`$exists`

下面的查询使用`$nor`操作符和`$exists`操作符:

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

此查询将返回以下所有文档:

包含值不等于`1.99`的`price`字段和值不等于`true`的`sale`字段

译者：李冠飞

校对：


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.mongoing.com/can-kao/yun-suan-fu/query-and-projection-operators/logical-query-operators/nor.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
