정의
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 권한 작업 없이도 mongod 인스턴스에서 db.currentOp( { "$ownOps": true } )를 실행하여 자신의 작업을 볼 수 있습니다.
예시
The following examples use the db.currentOp() method with various query documents to filter the output.
잠금을 기다리는 쓰기 작업
다음 예에서는 잠금을 기다리는 모든 쓰기 작업에 대한 정보를 반환합니다.
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.