定義
db.currentOp()重要
We recommend using the
$currentOpaggregation stage instead of thecurrentOpcommand (deprecated with version 6.2) and thedb.currentOp()method.Returns a document that contains information on in-progress operations for the database instance. The
db.currentOp()method wraps the database commandcurrentOp.注意
Starting in MongoDB 5.0, the
$currentOpaggregation stage is used when running the helper methoddb.currentOp()withmongosh.Given this, in the 5.0 version of the shell and with mongosh,
db.currentOp()result sets are not subject to the 16MB BSON document return size document return size limit for documents of the previous legacymongoversions.
互換性
このメソッドは、次の環境でホストされている配置で使用できます。
- MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud
重要
This command is not supported in M0 and Flex clusters. For more information, see Unsupported Commands.
MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン
MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン
構文
db.currentOp() の形式は次のとおりです。
db.currentOp(<operations>)
db.currentOp() can take the following optional argument:
動作
db.currentOp() フィルター ドキュメントまたはブール値 パラメータを受け入れることができます。
If you pass a filter document to db.currentOp(), the output returns information only for the current operations that match the filter. The filter document can contain:
フィールド | 説明 |
|---|---|
| ブール値。
|
| ブール値。 If the document includes |
<filter> | Specify filter conditions on the Output Fields. See Examples. If the document includes |
Passing in true to db.currentOp() is equivalent to passing in a document of { "$all": true }. The following operations are equivalent:
db.currentOp(true) db.currentOp( { "$all": true } )
db.currentOp() and the database profiler report the same basic diagnostic information for all CRUD operations, including the following:
getMore(OP_GET_MORE とcommand)
これらの操作は低速クエリのログにも含まれます。 低速クエリ ロギングの詳細については、 slowOpThresholdMsを参照してください。
アクセス制御
authorization で実行されているシステムでは、ユーザーに inprog 特権アクションを含むアクセス権が必要です。
inprog 特権アクションがなくても、ユーザーは db.currentOp( { "$ownOps": true } ) を mongod インスタンスで実行し、自分の操作を表示できます。
例
The following examples use the db.currentOp() method with various query documents to filter the output.
ロックを待機する書込み (write) 操作
次の例では、ロックを待機しているすべての書込み (write) 操作に関する情報を返します。
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\./ } )
アクティブなインデックス操作
次の例では、任意の数のフィールドに対するインデックス作成操作に関する情報を返します。
db.getSiblingDB("admin").aggregate( [ { $currentOp : { idleConnections: true } }, { $match: { $or: [ { "op": "command", "command.createIndexes": { $exists: true } }, { "op": "none", "msg": /^Index Build/ } ] } } ] )
注意
アクティブインデックスの作成操作は、ローリングインデックス構築には適用されません。
出力例
The following is a prototype of db.currentOp() output.
以下は、スタンドアロンで実行した場合の currentOp 出力のプロトタイプです。
{ "inprog": [ { "type" : <string>, "host" : <string>, "desc" : <string>, "connectionId" : <number>, "client" : <string>, "appName" : <string>, "clientMetadata" : <document>, "active" : <boolean>, "currentOpTime" : <string>, "effectiveUsers" : [ { "user" : <string>, "db" : <string> } ], "opid" : <number>, "lsid" : { "id" : <UUID>, "uid" : <BinData> }, "secs_running" : <Long()>, "microsecs_running" : <number>, "op" : <string>, "ns" : <string>, "command" : <document>, "queryFramework" : <string>, "planSummary": <string>, "inUseTrackedMemBytes": <Long()>, // Starting in 8.3 "peakTrackedMemBytes": <Long()>, // Starting in 8.3 "cursor" : { // only for getMore operations "cursorId" : <Long()>, "createdDate" : <ISODate()>, "lastAccessDate" : <ISODate()>, "nDocsReturned" : <Long()>, "nBatchesReturned" : <Long()>, "noCursorTimeout" : <boolean>, "tailable" : <boolean>, "awaitData" : <boolean>, "originatingCommand" : <document>, "planSummary" : <string>, "operationUsingCursorId" : <Long()> }, "msg": <string>, "progress" : { "done" : <number>, "total" : <number> }, "killPending" : <boolean>, "numYields" : <number>, "dataThroughputLastSecond" : <number>, "dataThroughputAverage" : <number>, "locks" : { "ParallelBatchWriterMode" : <string>, "ReplicationStateTransition" : <string>, "Global" : <string>, "Database" : <string>, "Collection" : <string>, "Metadata" : <string>, "oplog" : <string> }, "waitingForLock" : <boolean>, "lockStats" : { "ParallelBatchWriterMode" : { "acquireCount": { "r": <NumberLong>, "w": <NumberLong>, "R": <NumberLong>, "W": <NumberLong> }, "acquireWaitCount": { "r": <NumberLong>, "w": <NumberLong>, "R": <NumberLong>, "W": <NumberLong> }, "timeAcquiringMicros" : { "r" : Long(0), "w" : Long(0), "R" : Long(0), "W" : Long(0) }, "deadlockCount" : { "r" : Long(0), "w" : Long(0), "R" : Long(0), "W" : Long(0) } }, "ReplicationStateTransition" : { ... }, "Global": { ... }, "Database" : { ... }, ... } }, ... ], "fsyncLock": <boolean>, "info": <string>, "ok": <num> }
以下は、レプリカセットのプライマリで実行した場合の currentOp 出力のプロトタイプです。
{ "inprog": [ { "type" : <string>, "host" : <string>, "desc" : <string>, "connectionId" : <number>, "client" : <string>, "appName" : <string>, "clientMetadata" : <document>, "lsid" : { "id" : <UUID>, "uid" : <BinData> }, "transaction" : { "parameters" : { "txnNumber" : <Long()>, "autocommit" : <boolean>, "readConcern" : { "level" : <string> } }, "readTimestamp" : <Timestamp>, "startWallClockTime" : <string>, "timeOpenMicros" : <Long()>, "timeActiveMicros" : <Long()>, "timeInactiveMicros" : <Long()>, "expiryTime" : <string>, }, "active" : <boolean>, "currentOpTime" : <string>, "effectiveUsers" : [ { "user" : <string>, "db" : <string> } ], "opid" : <number>, "secs_running" : <Long()>, "microsecs_running" : <number>, "op" : <string>, "ns" : <string>, "command" : <document>, "originatingCommand" : <document>, "queryFramework" : <string>, "planSummary": <string>, "inUseTrackedMemBytes": <Long()>, // Starting in 8.3 "peakTrackedMemBytes": <Long()>, // Starting in 8.3 "prepareReadConflicts" : <Long()>, "writeConflicts" : <Long()>, "cursor" : { // only for getMore operations "cursorId" : <Long()>, "createdDate" : <ISODate()>, "lastAccessDate" : <ISODate()>, "nDocsReturned" : <Long()>, "nBatchesReturned" : <Long()>, "noCursorTimeout" : <boolean>, "tailable" : <boolean>, "awaitData" : <boolean>, "originatingCommand" : <document>, "planSummary" : <string>, "operationUsingCursorId" : <Long()> }, "msg": <string>, "progress" : { "done" : <number>, "total" : <number> }, "killPending" : <boolean>, "numYields" : <number>, "dataThroughputLastSecond" : <number>, "dataThroughputAverage" : <number>, "locks" : { "ParallelBatchWriterMode" : <string>, "ReplicationStateTransition" : <string>, "Global" : <string>, "Database" : <string>, "Collection" : <string>, "Metadata" : <string>, "oplog" : <string> }, "waitingForLock" : <boolean>, "lockStats" : { "ParallelBatchWriterMode" : { "acquireCount": { "r": <NumberLong>, "w": <NumberLong>, "R": <NumberLong>, "W": <NumberLong> }, "acquireWaitCount": { "r": <NumberLong>, "w": <NumberLong>, "R": <NumberLong>, "W": <NumberLong> }, "timeAcquiringMicros" : { "r" : Long(0), "w" : Long(0), "R" : Long(0), "W" : Long(0) }, "deadlockCount" : { "r" : Long(0), "w" : Long(0), "R" : Long(0), "W" : Long(0) } }, "ReplicationStateTransition" : { ... }, "Global" : { ... }, "Database" : { ... }, ... } }, ... ], "fsyncLock": <boolean>, "info": <string>, "ok": <num>, "operationTime": <timestamp>, "$clusterTime": <document> }
以下は、シャーディングされたクラスターの mongos で実行された場合の currentOp 出力の例です(フィールドは、報告される操作によって異なる場合があります)。
{ "inprog": [ { "shard": <string>, "type" : <string>, "host" : <string>, "desc" : <string>, "connectionId" : <number>, "client_s" : <string>, "appName" : <string>, "clientMetadata" : <document>, "lsid" : { "id" : <UUID>, "uid" : <BinData> }, "transaction" : { "parameters" : { "txnNumber" : <Long()>, "autocommit" : <boolean>, "readConcern" : { "level" : <string> } }, "readTimestamp" : <Timestamp>, "startWallClockTime" : <string>, "timeOpenMicros" : <Long()>, "timeActiveMicros" : <Long()>, "timeInactiveMicros" : <Long()>, "expiryTime" : <string>, }, "active" : <boolean>, "currentOpTime" : <string>, "effectiveUsers" : [ { "user" : <string>, "db" : <string> } ], "runBy" : [ { "user" : <string>, "db" : <string> } ], "twoPhaseCommitCoordinator" : { "lsid" : { "id" : <UUID>, "uid" : <BinData> }, "txnNumber" : <NumberLong>, "numParticipants" : <NumberLong>, "state" : <string>, "commitStartTime" : <ISODate>, "hasRecoveredFromFailover" : <boolean>, "stepDurations" : <document>, "decision" : <document>, "deadline" : <ISODate> } "opid" : <string>, "secs_running" : <Long()>, "microsecs_running" : <number>, "op" : <string>, "ns" : <string>, "command" : <document>, "configTime" : <Timestamp>, // Starting in 5.0 "topologyTime" : <Timestamp>, // Starting in 5.0 "queryFramework" : <string>, // Starting in 6.2 "planSummary": <string>, "inUseTrackedMemBytes": <Long()>, // Starting in 8.3 "peakTrackedMemBytes": <Long()>, // Starting in 8.3 "prepareReadConflicts" : <Long()>, "writeConflicts" : <Long()>, "cursor" : { // only for getMore operations "cursorId" : <Long()>, "createdDate" : <ISODate()>, "lastAccessDate" : <ISODate()>, "nDocsReturned" : <Long()>, "nBatchesReturned" : <Long()>, "noCursorTimeout" : <boolean>, "tailable" : <boolean>, "awaitData" : <boolean>, "originatingCommand" : <document>, "planSummary" : <string>, "operationUsingCursorId" : <Long()> }, "msg": <string>, "progress" : { "done" : <number>, "total" : <number> }, "killPending" : <boolean>, "numYields" : <number>, "dataThroughputLastSecond" : <number>, "dataThroughputAverage" : <number>, "locks" : { "ParallelBatchWriterMode" : <string>, "ReplicationStateTransition" : <string>, "Global" : <string>, "Database" : <string>, "Collection" : <string>, "Metadata" : <string>, "DDLDatabase" : <string>, "DDLCollection" : <string>, "oplog" : <string> }, "waitingForLock" : <boolean>, "lockStats" : { "ParallelBatchWriterMode": { "acquireCount": { "r": <NumberLong>, "w": <NumberLong>, "R": <NumberLong>, "W": <NumberLong> }, "acquireWaitCount": { "r": <NumberLong>, "w": <NumberLong>, "R": <NumberLong>, "W": <NumberLong> }, "timeAcquiringMicros" : { "r" : Long(0), "w" : Long(0), "R" : Long(0), "W" : Long(0) }, "deadlockCount" : { "r" : Long(0), "w" : Long(0), "R" : Long(0), "W" : Long(0) } }, "ReplicationStateTransition" : { ... }, "Global" : { ... }, "Database" : { ... }, ... } }, ... ], "ok": <num>, "operationTime": <timestamp>, "$clusterTime": <document> }
具体的な出力例
これらの出力サンプルは、特定の操作に対する currentOp 出力を示しています。実際の出力を構成するフィールドは、サーバーのロールによって異なります。
リシャーディング出力の例
{ shard: '<string>', totalCopyTimeElapsedSecs: Long('<count>'), totalApplyTimeElapsedSecs: Long('<count>'), totalCriticalSectionTimeElapsedSecs: Long('<count>'), totalIndexBuildTimeElapsedSecs: Long('<count>'), indexesToBuild: Long('<count>'), indexesBuilt: Long('<count>'), oplogEntriesFetched: Long('<count>'), oplogEntriesApplied: Long('<count>'), insertsApplied: Long('<count>'), updatesApplied: Long('<count>'), deletesApplied: Long('<count>'), type: 'op', desc: 'ReshardingMetrics{Donor|Recipient|Coordinator}Service <reshardingUUID>', op: 'command', ns: '<database>.<collection>', originatingCommand: { reshardCollection: '<database>.<collection>', key: '<shardkey>', unique:'<boolean>', collation: { locale: 'simple' } }, totalOperationTimeElapsedSecs: Long('<count>'), recipientState: '<service state>', remainingOperationTimeEstimatedSecs: Long('<count>'), approxDocumentsToCopy: Long('<count>'), approxBytesToCopy: Long('<count>'), bytesCopied: Long('<count>'), countWritesToStashCollections: Long('<count>'), documentsCopied: Long('<count>'), provenance: 'reshardCollection' }
出力フィールド
For a complete list of db.currentOp() output fields, see currentOp.