AI エージェント向け: ドキュメントインデックスは https://www.mongodb.com/ja-jp/docs/llms.txt で利用できます。すべてのページの markdown バージョンは、いずれかの URL パスに .md を追加することで利用できます。

db.currentOp()(mongoshメソッド)

db.currentOp()

重要

currentOpデータベースコマンドはバージョン 6.2 以降では非推奨です。$currentOpcurrentOpコマンドとそのmongosh ヘルパーメソッドdb.currentOp() の代わりに、 集計ステージを使用します。

データベース インスタンスに対して進行中の操作に関する情報を含むドキュメントを返します。 db.currentOp()メソッドはデータベースコマンドcurrentOpをラップします。

注意

MongoDB 5.0 以降では、ヘルパー メソッド db.currentOp() を mongosh で実行するときに $currentOp 集計ステージが使用されます。

これを考慮すると、shell の 5.0 バージョンと mongosh では、db.currentOp() の結果セットは、前のレガシー mongo バージョンのドキュメントの 16MB BSON ドキュメント戻りサイズ制限を受けません。

このメソッドは、次の環境でホストされている配置で使用できます。

  • MongoDB Atlas はクラウドでの MongoDB 配置のためのフルマネージド サービスです

重要

このコマンドは、M0 および Flex クラスターではサポートされていません。詳細については、「 サポートされていないコマンド 」を参照してください。

  • MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン

  • MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン

db.currentOp() の形式は次のとおりです。

db.currentOp(<operations>)

db.currentOp() は、次の任意引数を取ることができます:

Parameter
タイプ
説明

ブール値またはドキュメント

任意。レポートする操作を指定します。ブール値またはドキュメントを渡すことができます。

  • アイドル接続とシステム操作に関する操作を含めるには、 true を指定します。

  • クエリ条件を含むドキュメントを指定して、条件に一致する操作のみを報告します。詳細については、「動作」を参照してください。

db.currentOp() フィルター ドキュメントまたはブール値 パラメータを受け入れることができます。

フィルター ドキュメントを db.currentOp() に渡すと、出力には、フィルターに一致する現在の操作に関する情報のみが返されます。フィルター ドキュメントには、以下の内容を含めることができます:

フィールド
説明

"$ownOps"

ブール値。true に設定すると、現在のユーザーの操作に関する情報のみが返されます。

mongod インスタンスでは、ユーザーはいつでも db.currentOp( { "$ownOps": true } ) を実行して自分の操作を表示できます。

"$all"

ブール値。true に設定すると、アイドル状態の接続の操作やシステム操作を含む、すべての操作に関する情報が返されます。詳細については、$currentOp(集計ステージ)を参照してください。

ドキュメントに、出力フィールド条件とともに "$all": true が含まれている場合は、"$all":true のみが適用されます。

<filter>

出力フィールドでフィルター条件を指定します。例を参照してください。

ドキュメントに、出力フィールド条件とともに "$all": true が含まれている場合は、"$all": true のみが適用されます。

true を db.currentOp() に渡すことは、{ "$all": true } のドキュメントを渡すのと同じです。次の操作は同等です。

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

db.currentOp()とデータベースプロファイラーが報告する基本的なCRUD情報は同じで、次のようなものがあります。

これらの操作は低速クエリのログにも含まれます。 低速クエリ ロギングの詳細については、 slowOpThresholdMsを参照してください。

authorization で実行されているシステムでは、ユーザーに inprog 特権アクションを含むアクセス権が必要です。

inprog 特権アクションがなくても、ユーザーは db.currentOp( { "$ownOps": true } ) を mongod インスタンスで実行し、自分の操作を表示できます。

次の例では、さまざまなクエリ ドキュメントで db.currentOp() メソッドを使用して出力をフィルタリングします。

次の例では、ロックを待機しているすべての書込み (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/ } ] } }] )

注意

アクティブインデックスの作成操作は、ローリングインデックス構築には適用されません。

以下は db.currentOp() 出力のプロトタイプです。

以下は、スタンドアロンで実行した場合の 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>, "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>, "waitingForLatch" : { "timestamp" : <ISODate()>, "captureName" : <string> }, "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 出力を示しています。実際の出力を構成するフィールドは、サーバーのロールによって異なります。

{ type: "op", desc: "Resharding{Donor, Recipient, Coordinator}Service <reshardingUUID>", op: "command", ns: "<database>.<collection>", originatingCommand: { reshardCollection: "<database>.<collection>", key: <shardkey>, unique: <boolean>, collation: {locale: "simple"}, // Other options to the reshardCollection command are omitted // to decrease the likelihood the output is truncated. }, {donor, coordinator, recipient}State : "<service state>", approxDocumentsToCopy: NumberLong(<count>), approxBytesToCopy: NumberLong(<count>), bytesCopied: NumberLong(<count>), countWritesToStashCollections: NumberLong(<count>), countWritesDuringCriticalSection : NumberLong(<count>), countReadsDuringCriticalSection: NumberLong(<count>), deletesApplied: NumberLong(<count>), documentsCopied: NumberLong(<count>), insertsApplied: NumberLong(<count>), oplogEntriesFetched: NumberLong(<count>), oplogEntriesApplied: NumberLong(<count>), remainingOperationTimeEstimatedSecs: NumberLong(<count>), allShardsLowestRemainingOperationTimeEstimatedSecs: NumberLong(<estimate>), allShardsHighestRemainingOperationTimeEstimatedSecs: NumberLong(<estimate>), totalApplyTimeElapsedSecs: NumberLong(<count>), totalCopyTimeElapsedSecs: NumberLong(<count>), totalCriticalSectionTimeElapsedSecs : NumberLong(<count>), totalOperationTimeElapsedSecs: NumberLong(<count>), updatesApplied: NumberLong(<count>),}
{ type: "op", desc: "GlobalIndex{Donor, Recipient, Coordinator}Service <globalIndexUUID}", op: "command", ns: "<database>.<collection>", originatingCommand: { createIndexes: "<database>.<collection>", key: <indexkeypattern>, unique: <boolean>, <Additional createIndexes options> }, {donor, coordinator, recipient}State : "<service state>", approxDocumentsToScan: Long(<count>), approxBytesToScan: Long(<count>), bytesWrittenFromScan: Long(<count>), countWritesToStashCollections: Long(<count>), countWritesDuringCriticalSection : Long(<count>), countReadsDuringCriticalSection: Long(<count>), keysWrittenFromScan: Long(<count>), remainingOperationTimeEstimatedSecs: Long(<count>), allShardsLowestRemainingOperationTimeEstimatedSecs: Long(<estimate>), allShardsHighestRemainingOperationTimeEstimatedSecs: Long(<estimate>), totalCopyTimeElapsedSecs: Long(<count>), totalCriticalSectionTimeElapsedSecs : Long(<count>), totalOperationTimeElapsedSecs: Long(<count>),}

db.currentOp()出力フィールドの完全なリストについては、 currentOp を参照してください。