cursor.comment()

在本页面

Definition

  • cursor. comment ( )
    • 3.2 版中的新功能。

在查询中添加一个comment字段。

cursor.comment()具有以下语法:

cursor.comment( <string> )

comment()具有以下参数:

ParameterTypeDescription
commentstring应用于查询的 Comments。

Behavior

comment()将 Comments 字符串与 find 操作相关联。这样可以更轻松地在以下诊断输出中跟踪特定查询:

有关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日志的摘录。它已被格式化以提高可读性。

Important

QUERY的详细级别必须大于0。参见配置日志详细级别

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
}