On this page本页内容
cursor.comment()
This is a mongosh
method. This is not the documentation for Node.js
or other programming language specific driver methods.
In most cases, mongosh
methods work the same way as the legacy mongo
shell methods. However, some legacy methods are unavailable in mongosh
.
For the legacy mongo
shell documentation, refer to the documentation for the corresponding MongoDB Server release:
For MongoDB API drivers, refer to the language specific MongoDB driver documentation.
Adds a 向查询中添加comment
field to the query.comment
字段。
cursor.comment()
has the following syntax:具有以下语法:
cursor.comment( <string> )
comment()
has the following parameter:具有以下参数:
comment | string |
comment()
associates a comment string with the find operation. 将注释字符串与查找操作相关联。This can make it easier to track a particular query in the following diagnostic outputs:这样可以更容易地跟踪以下诊断输出中的特定查询:
system.profile
QUERY
log componentQUERY
日志组件db.currentOp()
See configure log verbosity for the 有关mongod
log, the Database Profiler tutorial, or the db.currentOp()
command.mongod
日志、数据库探查器教程或dbcurrentOp()
命令,请参阅configure log verbosity。
The following operation attaches a comment to a query on the 以下操作将注释附加到restaurants
collection:restaurants
集合的查询:
db.restaurants.find( { "borough" : "Manhattan" } ).comment( "Find all Manhattan restaurants" )
system.profile
The following is an excerpt from the 以下是system.profile
:system.profile
的摘录:
{ "op" : "query", "ns" : "guidebook.restaurant", "query" : { "find" : "restaurant", "filter" : { "borough" : "Manhattan" }, "comment" : "Find all Manhattan restaurants" }, ... }
mongod
logThe following is an excerpt from the 以下是蒙古日志的摘录。它已格式化以便于阅读。mongod
log. It has been formatted for readability.
The verbosity level for QUERY
must be greater than 0
. QUERY
的详细级别必须大于0
。See Configure Log Verbosity Levels请参阅配置日志详细级别
2015-11-23T13:09:16.202-05:00 I COMMAND [conn1] command guidebook.restaurant command: find { find: "restaurant", filter: { "borough" : "Manhattan" }, comment: "Find all Manhattan restaurants" } ...
db.currentOp()
Suppose the following operation is currently running on a 假设以下操作当前正在mongod
instance:mongod
实例上运行:
db.restaurants.find( { "borough" : "Manhattan" } ).comment("Find all Manhattan restaurants")
Running the 运行db.currentOp()
command returns the following: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 }