运算符 $comment 将注释添加到查询,以帮助在日志和探查器输出中识别它们。 这对于用于调试和监测数据库操作非常有用。
语法
{
$comment: <string>
}
参数
| 参数 | DESCRIPTION |
|---|---|
string |
一个字符串,带有要包含在查询中的注释。 |
例子
请考虑商店集合中的这个示例文档。
{
"_id": "40d6f4d7-50cd-4929-9a07-0a7a133c2e74",
"name": "Proseware, Inc. | Home Entertainment Hub - East Linwoodbury",
"location": {
"lat": 70.1272,
"lon": 69.7296
},
"staff": {
"totalStaff": {
"fullTime": 19,
"partTime": 20
}
},
"sales": {
"totalSales": 151864,
"salesByCategory": [
{
"categoryName": "Sound Bars",
"totalSales": 2120
},
{
"categoryName": "Home Theater Projectors",
"totalSales": 45004
}
]
},
"promotionEvents": [
{
"eventName": "Massive Markdown Mania",
"promotionalDates": {
"startDate": {
"Year": 2023,
"Month": 6,
"Day": 29
},
"endDate": {
"Year": 2023,
"Month": 7,
"Day": 9
}
},
"discounts": [
{
"categoryName": "DVD Players",
"discountPercentage": 14
}
]
}
]
}
示例 1:查找总销售额超过 100,000 的商店,并添加日志注释以供参考
此查询检索总销售额超过 100,000 的商店,并包括用于在日志中轻松识别的注释。
db.stores.find(
{ "sales.totalSales": { $gt: 100000 } },
{ name: 1, "sales.totalSales": 1 }
).comment("Query to find high-performing stores")
此查询返回以下结果。
[
{
"_id": "40d6f4d7-50cd-4929-9a07-0a7a133c2e74",
"name": "Proseware, Inc. | Home Entertainment Hub - East Linwoodbury",
"sales": {
"totalSales": 151864
}
}
]
相关内容
- 查看有关 从 MongoDB 迁移到适用于 MongoDB 的 Azure Cosmos DB (vCore) 的选项。
- 详细了解 与 MongoDB 的功能兼容性。