> For the complete documentation index, see [llms.txt](https://docs.mongoing.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mongoing.com/can-kao/yun-suan-fu/query-and-projection-operators/comment.md).

# $comment

在本页面

* [定义](#definition)
* [行为](#behavior)
* [例子](#example)

## 定义

**$comment**

`$comment`查询操作符将注释与任何具有查询谓词的表达式关联起来。

由于注释会传播到`profile`日志，因此添加注释可以使您的个人资料数据更易于解释和跟踪。

`$comment`运算符的形式为：

```
db.collection.find( { <query>, $comment: <comment> } )
```

## 行为

您可以将\_ `$comment`与任何带查询谓词的表达式一起使用，例如聚合管道中`db.collection.update()`或聚合`$match`阶段中的查询谓词 。有关示例，请参见对聚合表达式附加注释。

## 例子

### 附加评论到`find`

以下示例`$comment`在 `find()`操作中添加了：

```
db.records.find(
   {
     x: { $mod: [ 2, 0 ] },
     $comment: "Find even values."
   }
)
```

### 在聚合表达式上附加注释

您可以对`$comment`带查询谓词的任何表达式使用。

以下示例在`$match`阶段中使用运算符`$comment`来阐明操作：

```
db.records.aggregate( [
   { $match: { x: { $gt: 0 }, $comment: "Don't allow negative inputs." } },
   { $group : { _id: { $mod: [ "$x", 2 ] }, total: { $sum: "$x" } } }
] )
```

> **也可以看看**
>
> `$comment`

译者：李冠飞

校对：


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
