On this page
cursor.comment()
在本页面
Definition
cursor.
comment
( )- 3.2 版中的新功能。
在查询中添加一个comment
字段。
cursor.comment()具有以下语法:
cursor.comment( <string> )
comment()具有以下参数:
Parameter | Type | Description |
---|---|---|
comment |
string | 应用于查询的 Comments。 |
Behavior
comment()将 Comments 字符串与 find 操作相关联。这样可以更轻松地在以下诊断输出中跟踪特定查询:
The system.profile
有关mongod日志,数据库探查器教程或db.currentOp()命令,请参见配置日志详细程度。
Example
以下操作在restaurants
集合的查询上附加 Comments:
db.restaurants.find(
{ "borough" : "Manhattan" }
).comment( "Find all Manhattan restaurants" )
Output Examples
system.profile
以下是system.profile的摘录:
{
"op" : "query",
"ns" : "guidebook.restaurant",
"query" : {
"find" : "restaurant",
"filter" : {
"borough" : "Manhattan"
},
"comment" : "Find all Manhattan restaurants"
},
...
}
mongod log
以下是mongod日志的摘录。它已被格式化以提高可读性。
2015-11-23T13:09:16.202-0500 I COMMAND [conn1]
command guidebook.restaurant command: find {
find: "restaurant",
filter: { "borough" : "Manhattan" },
comment: "Find all Manhattan restaurants"
}
...
db.currentOp()
假设当前在mongod实例上运行以下操作:
db.restaurants.find(
{ "borough" : "Manhattan" }
).comment("Find all Manhattan restaurants")
运行db.currentOp()命令将返回以下内容:
{
"inprog" : [
{
"host" : "198.51.100.1:27017",
"desc" : "conn3",
"connectionId" : 3,
...
"op" : "query",
"ns" : "test.$cmd",
"command" : {
"find" : "restaurants",
"filter" : {
"borough" : "Manhattan"
},
"comment" : "Find all Manhattan restaurants",
"$db" : "test"
},
"numYields" : 0,
...
}
],
"ok" : 1
}