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

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

db.currentOp()

重要

We recommend using the $currentOp aggregation stage instead of the currentOp command (deprecated with version 6.2) and the db.currentOp() method.

Returns a document that contains information on in-progress operations for the database instance. The db.currentOp() method wraps the database command currentOp.

注意

Starting in MongoDB 5.0, the $currentOp aggregation stage is used when running the helper method db.currentOp() with mongosh.

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 legacy mongo versions.

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

  • 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:

Parameter
タイプ
説明

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

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

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

  • Specify a document with query conditions to report only on those operations that match the conditions. See Behavior for details.

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:

フィールド
説明

"$ownOps"

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

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

"$all"

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

If the document includes "$all": true along with Output Fields conditions, only the "$all":true applies.

<filter>

Specify filter conditions on the Output Fields. See Examples.

If the document includes "$all": true along with Output Fields conditions, only the "$all": true applies.

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:

これらの操作は低速クエリのログにも含まれます。 低速クエリ ロギングの詳細については、 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) 操作に関する情報を返します。

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 出力を示しています。実際の出力を構成するフィールドは、サーバーのロールによって異なります。

{
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.