문서 메뉴
문서 홈
/
MongoDB 매뉴얼
/ / /

db.currentOp()

이 페이지의 내용

  • 정의
  • 호환성
  • 행동
  • 액세스 제어
  • 예제
  • 출력 예시
  • 특정 출력 예제
  • 출력 필드
db.currentOp()

데이터베이스 인스턴스의 진행 중인 작업에 대한 정보가 포함된 문서 를 반환합니다. db.currentOp() 메서드는 데이터베이스 명령 currentOp 을 래핑합니다.

currentOp 명령과 그 mongosh 헬퍼 메서드 db.currentOp() 대신 $currentOp 집계 단계를 사용합니다.

참고

MongoDB 5.0부터 $currentOp 집계 단계는 mongosh로 헬퍼 메서드 db.currentOp()를 실행할 때 사용됩니다.

이를 감안할 때 셸의 5.0 버전 및 mongosh의 경우 db.currentOp() 결과 세트에는 이전 레거시 mongo 버전의 문서에 대한 16MB BSON 문서 반환 크기 문서 반환 크기 제한이 적용되지 않습니다.

이 메서드는 다음 환경에서 호스팅되는 배포에서 사용할 수 있습니다.

  • MongoDB Atlas: 클라우드에서의 MongoDB 배포를 위한 완전 관리형 서비스

참고

이 명령은 모든 MongoDB Atlas 클러스터에서 지원됩니다. 모든 명령에 대한 자세한 내용은 지원되지 않는 명령을 참조하세요.

db.currentOp() 의 형식은 다음과 같습니다.

db.currentOp(<operations>)

db.currentOp()는 다음과 같은 선택적 인수를 사용할 수 있습니다.

매개 변수
유형
설명
부울 또는 문서

선택 사항. 보고할 작업을 지정합니다. 불(boolean) 또는 문서를 전달할 수 있습니다:

  • 유휴 연결 및 시스템 작업에 대한 작업을 포함하려면 true를 지정합니다.

  • 조건과 일치하는 작업에 대해서만 보고하려면 쿼리 조건이 포함된 문서를 지정합니다. 자세한 내용은 동작을 참조하세요.

db.currentOp() 는 필터 문서 또는 부울 매개변수를 받을 수 있습니다.

필터 문서를 db.currentOp()로 전달하면 출력은 필터와 일치하는 현재 작업에 대한 정보만 반환합니다. 필터 문서에는 다음이 포함될 수 있습니다.

필드
설명
"$ownOps"

부울. true로 설정하면 현재 사용자의 연산에 대한 정보만 반환합니다.

사용자는 언제든지 mongod 인스턴스에서 db.currentOp( { "$ownOps": true } )를 실행하여 작업을 확인할 수 있습니다.

"$all"

부울. true로 설정하면 유휴 연결에 대한 연산 및 시스템 연산을 포함한 모든 연산에 대한 정보를 반환합니다.

문서에 출력 필드 조건과 함께 "$all": true가 포함되어 있는 경우 "$all":true만 적용됩니다.

<filter>

출력 필드에 필터 조건을 지정합니다. 예시를 참조하세요.

문서에 출력 필드 조건과 함께 "$all": true가 포함되어 있는 경우 "$all": true만 적용됩니다.

db.currentOp()true를 전달하는 것은 { "$all": true }의 문서를 전달하는 것과 같습니다. 다음 작업은 이에 해당합니다.

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

db.currentOp()데이터베이스 프로파일러는 다음을 포함하여 모든 CRUD 작업에 대해 동일한 기본 진단 정보를 보고합니다.

이러한 작업은 느린 쿼리 로깅에도 포함됩니다. 느린 쿼리 로깅에 대한 자세한 내용은 slowOpThresholdMs 를 참조하세요.

authorization로 실행되는 시스템에서는 사용자에게 inprog 권한 작업이 포함된 액세스 권한이 있어야 합니다.

사용자는 inprog 권한 작업 없이도 mongod 인스턴스에서 db.currentOp( { "$ownOps": true } )를 실행하여 자신의 작업을 볼 수 있습니다.

다음도 참조하세요.

다음 예시에서는 db.currentOp() 메서드를 다양한 쿼리 문서와 함께 사용하여 출력을 필터링합니다.

다음 예에서는 잠금을 기다리는 모든 쓰기 작업에 대한 정보를 반환합니다.

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.adminCommand(
{
currentOp: true,
$or: [
{ op: "command", "command.createIndexes": { $exists: true } },
{ op: "command", "command.$truncated": /^\{ createIndexes/ },
{ 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" : <NumberLong()>,
"microsecs_running" : <number>,
"op" : <string>,
"ns" : <string>,
"command" : <document>,
"queryFramework" : <string>,
"planSummary": <string>,
"cursor" : { // only for getMore operations
"cursorId" : <NumberLong()>,
"createdDate" : <ISODate()>,
"lastAccessDate" : <ISODate()>,
"nDocsReturned" : <NumberLong()>,
"nBatchesReturned" : <NumberLong()>,
"noCursorTimeout" : <boolean>,
"tailable" : <boolean>,
"awaitData" : <boolean>,
"originatingCommand" : <document>,
"planSummary" : <string>,
"operationUsingCursorId" : <NumberLong()>
},
"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" : NumberLong(0),
"w" : NumberLong(0),
"R" : NumberLong(0),
"W" : NumberLong(0)
},
"deadlockCount" : {
"r" : NumberLong(0),
"w" : NumberLong(0),
"R" : NumberLong(0),
"W" : NumberLong(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" : <NumberLong()>,
"autocommit" : <boolean>,
"readConcern" : {
"level" : <string>
}
},
"readTimestamp" : <Timestamp>,
"startWallClockTime" : <string>,
"timeOpenMicros" : <NumberLong()>,
"timeActiveMicros" : <NumberLong()>,
"timeInactiveMicros" : <NumberLong()>,
"expiryTime" : <string>,
},
"active" : <boolean>,
"currentOpTime" : <string>,
"effectiveUsers" : [
{
"user" : <string>,
"db" : <string>
}
],
"opid" : <number>,
"secs_running" : <NumberLong()>,
"microsecs_running" : <number>,
"op" : <string>,
"ns" : <string>,
"command" : <document>,
"originatingCommand" : <document>,
"queryFramework" : <string>,
"planSummary": <string>,
"prepareReadConflicts" : <NumberLong()>,
"writeConflicts" : <NumberLong()>,
"cursor" : { // only for getMore operations
"cursorId" : <NumberLong()>,
"createdDate" : <ISODate()>,
"lastAccessDate" : <ISODate()>,
"nDocsReturned" : <NumberLong()>,
"nBatchesReturned" : <NumberLong()>,
"noCursorTimeout" : <boolean>,
"tailable" : <boolean>,
"awaitData" : <boolean>,
"originatingCommand" : <document>,
"planSummary" : <string>,
"operationUsingCursorId" : <NumberLong()>
},
"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" : NumberLong(0),
"w" : NumberLong(0),
"R" : NumberLong(0),
"W" : NumberLong(0)
},
"deadlockCount" : {
"r" : NumberLong(0),
"w" : NumberLong(0),
"R" : NumberLong(0),
"W" : NumberLong(0)
}
},
"ReplicationStateTransition" : {
...
},
"Global" : {
...
},
"Database" : {
...
},
...
}
},
...
],
"fsyncLock": <boolean>,
"info": <string>,
"ok": <num>,
"operationTime": <timestamp>,
"$clusterTime": <document>
}

다음은 currentOp mongos 샤드 cluster의 에서 실행할 때 출력의 예입니다(필드는 보고되는 작업에 따라 다를 수 있음).

{
"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" : <NumberLong()>,
"autocommit" : <boolean>,
"readConcern" : {
"level" : <string>
}
},
"readTimestamp" : <Timestamp>,
"startWallClockTime" : <string>,
"timeOpenMicros" : <NumberLong()>,
"timeActiveMicros" : <NumberLong()>,
"timeInactiveMicros" : <NumberLong()>,
"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" : <NumberLong()>,
"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" : <NumberLong()>,
"writeConflicts" : <NumberLong()>,
"cursor" : { // only for getMore operations
"cursorId" : <NumberLong()>,
"createdDate" : <ISODate()>,
"lastAccessDate" : <ISODate()>,
"nDocsReturned" : <NumberLong()>,
"nBatchesReturned" : <NumberLong()>,
"noCursorTimeout" : <boolean>,
"tailable" : <boolean>,
"awaitData" : <boolean>,
"originatingCommand" : <document>,
"planSummary" : <string>,
"operationUsingCursorId" : <NumberLong()>
},
"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" : NumberLong(0),
"w" : NumberLong(0),
"R" : NumberLong(0),
"W" : NumberLong(0)
},
"deadlockCount" : {
"r" : NumberLong(0),
"w" : NumberLong(0),
"R" : NumberLong(0),
"W" : NumberLong(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: NumberLong(<count>),
approxBytesToScan: NumberLong(<count>),
bytesWrittenFromScan: NumberLong(<count>),
countWritesToStashCollections: NumberLong(<count>),
countWritesDuringCriticalSection : NumberLong(<count>),
countReadsDuringCriticalSection: NumberLong(<count>),
keysWrittenFromScan: NumberLong(<count>),
remainingOperationTimeEstimatedSecs: NumberLong(<count>),
allShardsLowestRemainingOperationTimeEstimatedSecs: NumberLong(<estimate>),
allShardsHighestRemainingOperationTimeEstimatedSecs: NumberLong(<estimate>),
totalCopyTimeElapsedSecs: NumberLong(<count>),
totalCriticalSectionTimeElapsedSecs : NumberLong(<count>),
totalOperationTimeElapsedSecs: NumberLong(<count>),
}

db.currentOp() 출력 필드의 전체 목록은 currentOp를 참조하세요.

돌아가기

db.createView

다음

db.dropDatabase