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

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

db.currentOp()

重要

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

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

注意

MongoDB5.0 以降では、ヘルパーメソッド$currentOpdb.currentOp() とともに実行中ときにmongosh 集計ステージが使用されます。

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

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

  • MongoDB Atlas はクラウドでの MongoDB 配置のための完全管理サービスです

重要

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

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

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

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

db.currentOp(<operations>)

db.currentOp() can take the following optional argument:

Parameter
タイプ
説明

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

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

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

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

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>

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

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/ }
]
}
}
] )

注意

Active Indexing Operations do not apply to rolling index builds.

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>,
"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 出力のプロトタイプです。

{
"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>,
"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>,
"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>,
"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>,
"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>,
"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" : {
...
},
...
}
},
...
],
"ok": <num>,
"operationTime": <timestamp>,
"$clusterTime": <document>
}

これらの出力サンプルは、特定の操作に対する 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>),
}

For a complete list of db.currentOp() output fields, see currentOp.