db.currentOp()

在本页面

Definition

Syntax

db.currentOp()的格式如下:

db.currentOp(<operations>)

db.currentOp()可以采用以下可选参数:

Parameter Type Description
operations 布尔值或文档 可选的。指定要报告的操作。可以传递布尔值或文档:



指定true以包括对空闲连接的操作和系统操作。
指定具有查询条件的文档,以仅报告与条件匹配的那些操作。有关详细信息,请参见Behavior

Behavior

db.currentOp()可以接受过滤器文档或布尔参数。

如果将筛选器文档传递给db.currentOp(),则输出仅返回与筛选器匹配的当前操作的信息。筛选器文档可以包含:

Field Description
"$ownOps" 布尔值。如果设置为true,则仅返回有关当前用户操作的信息。


mongod个实例上,用户始终可以运行db.currentOp( { "$ownOps": true } )来查看自己的操作。
3.2.9 版中的新功能。
| "$all" |布尔值。如果设置为true,则返回有关所有操作的信息,包括有关空闲连接的操作和系统操作。
如果文档包含"$all": trueOutput Fields条件,则仅"$all":true适用。
|<filter> |在Output Fields上指定过滤条件。参见Examples
如果文档包含"$all": trueOutput Fields条件,则仅"$all": true适用。

true传递到db.currentOp()等效于传递{ "$all": true }的文档。以下操作是等效的:

db.currentOp(true)
db.currentOp( { "$all": true } )

db.currentOpdatabase profiler报告所有 CRUD 操作的相同基本诊断信息,包括以下内容:

这些操作也包含在慢查询的日志 Logging(有关慢查询的日志的更多信息,请参见slowOpThresholdMs)。

Access Control

在以authorization运行的系统上,用户必须具有包括inprog特权操作的访问权限。

从 3.2.9 开始,即使没有inprog特权操作,用户也可以在mongod实例上运行db.currentOp( { "$ownOps": true } )以查看自己的操作。

Examples

以下示例将db.currentOp()方法与各种查询文档结合使用来过滤输出。

await 锁定的写操作

在版本 3.6 中更改。

下面的示例返回有关所有 await 锁定的写操作的信息:

db.currentOp(
   {
     "waitingForLock" : true,
     $or: [
        { "op" : { "$in" : [ "insert", "update", "remove" ] } },
        { "command.findandmodify": { $exists: true } }
    ]
   }
)

没有收益的有效操作

以下示例返回从未产生的所有活动运行操作的信息:

db.currentOp(
   {
     "active" : true,
     "numYields" : 0,
     "waitingForLock" : false
   }
)

特定数据库上的活动操作

以下示例返回有关运行时间超过 3 秒的数据库db1的所有活动操作的信息:

db.currentOp(
   {
     "active" : true,
     "secs_running" : { "$gt" : 3 },
     "ns" : /^db1\./
   }
)

有效的索引编制操作

在版本 3.6 中更改。

以下示例返回有关索引创建操作的信息:

db.adminCommand(
    {
      currentOp: true,
      $or: [
        { op: "command", "command.createIndexes": { $exists: true }  },
        { op: "none", "msg" : /^Index Build/ }
      ]
    }
)

Output Example

以下是db.currentOp()输出的原型。

Standalone
Replica Set (Primary)
Sharded Cluster (mongos)

The following is a prototype of the currentOp output when run on a standalone:

{
  "inprog": [
       {
         "host" : <string>,
         "desc" : <string>,
         "connectionId" : <number>,
         "client" : <string>,
         "appName" : <string>,
         "clientMetadata" : <document>,
         "active" : <boolean>,
         "currentOpTime" : <string>,
         "opid" : <number>,
         "secs_running" : <NumberLong()>,
         "microsecs_running" : <number>,
         "op" : <string>,
         "ns" : <string>,
         "command" : <document>,
         "originatingCommand" : <document>,
         "planSummary": <string>,
         "msg": <string>,
         "progress" : {
             "done" : <number>,
             "total" : <number>
         },
         "killPending" : <boolean>,
         "numYields" : <number>,
         "locks" : {
             "Global" : <string>,
             "MMAPV1Journal" : <string>,
             "Database" : <string>,
             "Collection" : <string>,
             "Metadata" : <string>,
             "oplog" : <string>
         },
         "waitingForLock" : <boolean>,
         "lockStats" : {
             "Global": {
                "acquireCount": {
                   "r": <NumberLong>,
                   "w": <NumberLong>,
                   "R": <NumberLong>,
                   "W": <NumberLong>
                },
                "acquireWaitCount": {
                   "r": <NumberLong>,
                   "w": <NumberLong>,
                   "R": <NumberLong>,
                   "W": <NumberLong>
                },
                "timeAcquiringMicros" : {
                   "r" : NumberLong(0),
                   "w" : NumberLong(0),
                   "R" : NumberLong(0),
                   "W" : NumberLong(0)
                },
                "deadlockCount" : {
                   "r" : NumberLong(0),
                   "w" : NumberLong(0),
                   "R" : NumberLong(0),
                   "W" : NumberLong(0)
                }
             },
             "MMAPV1Journal": {
                ...
             },
             "Database" : {
                ...
             },
             ...
         }
       },
       ...
   ],
   "fsyncLock": <boolean>,
   "info": <string>,
   "ok": 1
}

The following is a prototype of the currentOp output when run on a primary of a replica set:

{
  "inprog": [
       {
         "host" : <string>,
         "desc" : <string>,
         "connectionId" : <number>,
         "client" : <string>,
         "appName" : <string>,
         "clientMetadata" : <document>,
         "active" : <boolean>,
         "currentOpTime" : <string>,
         "opid" : <number>,
         "secs_running" : <NumberLong()>,
         "microsecs_running" : <number>,
         "op" : <string>,
         "ns" : <string>,
         "command" : <document>,
         "originatingCommand" : <document>,
         "planSummary": <string>,
         "msg": <string>,
         "progress" : {
             "done" : <number>,
             "total" : <number>
         },
         "killPending" : <boolean>,
         "numYields" : <number>,
         "locks" : {
             "Global" : <string>,
             "MMAPV1Journal" : <string>,
             "Database" : <string>,
             "Collection" : <string>,
             "Metadata" : <string>,
             "oplog" : <string>
         },
         "waitingForLock" : <boolean>,
         "lockStats" : {
             "Global": {
                "acquireCount": {
                   "r": <NumberLong>,
                   "w": <NumberLong>,
                   "R": <NumberLong>,
                   "W": <NumberLong>
                },
                "acquireWaitCount": {
                   "r": <NumberLong>,
                   "w": <NumberLong>,
                   "R": <NumberLong>,
                   "W": <NumberLong>
                },
                "timeAcquiringMicros" : {
                   "r" : NumberLong(0),
                   "w" : NumberLong(0),
                   "R" : NumberLong(0),
                   "W" : NumberLong(0)
                },
                "deadlockCount" : {
                   "r" : NumberLong(0),
                   "w" : NumberLong(0),
                   "R" : NumberLong(0),
                   "W" : NumberLong(0)
                }
             },
             "MMAPV1Journal": {
                ...
             },
             "Database" : {
                ...
             },
             ...
         }
       },
       ...
   ],
   "fsyncLock": <boolean>,
   "info": <string>,
   "ok": <num>,
   "operationTime": <timestamp>,
   "$clusterTime": <document>
}

The following is a prototype of the currentOp output when run on a mongos of a sharded cluster:

{
   "inprog": [
        {
          "shard" : <string>,
          "host" : <string>,
          "desc" : <string>,
          "connectionId" : <number>,
          "client_s" : <string>,
          "appName" : <string>,
          "clientMetadata" : <document>,
          "active" : <boolean>,
          "currentOpTime": <string>,
          "opid" : <string>, // "<shard>:<opid>"
          "secs_running" : <NumberLong()>,
          "microsecs_running" : <number>,
          "op" : <string>,
          "ns" : <string>,
          "command" : <document>,
          "originatingCommand" : <document>,
          "planSummary": <string>,
          "msg": <string>,
          "progress" : {
              "done" : <number>,
              "total" : <number>
          },
          "killPending" : <boolean>,
          "numYields" : <number>,
          "locks" : {
              "Global" : <string>,
              "Database" : <string>,
              "Collection" : <string>,
              "Metadata" : <string>,
              "oplog" : <string>
          },
          "waitingForLock" : <boolean>,
          "lockStats" : {
              "Global": {
                 "acquireCount": {
                    "r": <NumberLong>,
                    "w": <NumberLong>,
                    "R": <NumberLong>,
                    "W": <NumberLong>
                 },
                 "acquireWaitCount": {
                    "r": <NumberLong>,
                    "w": <NumberLong>,
                    "R": <NumberLong>,
                    "W": <NumberLong>
                 },
                 "timeAcquiringMicros" : {
                    "r" : NumberLong(0),
                    "w" : NumberLong(0),
                    "R" : NumberLong(0),
                    "W" : NumberLong(0)
                 },
                 "deadlockCount" : {
                    "r" : NumberLong(0),
                    "w" : NumberLong(0),
                    "R" : NumberLong(0),
                    "W" : NumberLong(0)
                 }
              },
              "Database" : {
                 ...
              },
              ...
          }
        },
        ...
    ],
   "ok": <num>,
   "operationTime": <timestamp>,
   "$clusterTime": <document>
 }

Output Fields

有关db.currentOp()输出字段的完整列表,请参见currentOp

首页