Definition定义
db.currentOp()-
Important
ThecurrentOpdatabase command is deprecated since version 6.2. Use the$currentOpaggregation stage instead of thecurrentOpcommand and itsmongoshhelper methoddb.currentOp().currentOp数据库命令自6.2版本起已弃用。使用$currentOp聚合阶段,而不是currentOp命令及其mongosh辅助方法db.currentOp()。Returns a document that contains information on in-progress operations for the database instance.返回一个文档,其中包含有关数据库实例正在进行的操作的信息。Thedb.currentOp()method wraps the database commandcurrentOp.db.currentOp()方法封装数据库命令currentOp。Note
Starting in MongoDB 5.0, the从MongoDB 5.0开始,在用$currentOpaggregation stage is used when running the helper methoddb.currentOp()withmongosh.mongosh运行辅助方法db.currentOp()时使用$currentOp聚合阶段。Given this, in the 5.0 version of the shell and with mongosh,鉴于此,在5.0版本的shell和db.currentOp()result sets are not subject to the 16MB BSON document return size document return size limit for documents of the previous legacymongoversions.mongosh中,db.currentOp()结果集不受以前遗留mongo版本文档的16MB BSON文档返回大小文档返回大小限制。
Compatibility兼容性
This method is available in deployments hosted in the following environments:此方法在以下环境中托管的部署中可用:
- MongoDB Atlas
: The fully managed service for MongoDB deployments in the cloud:云中MongoDB部署的完全托管服务
Important
This command is not supported in M0 and Flex clusters. For more information, see Unsupported Commands.M0和Flex集群不支持此命令。有关详细信息,请参阅不支持的命令。
- MongoDB Enterprise
: The subscription-based, self-managed version of MongoDB:MongoDB的基于订阅的自我管理版本 - MongoDB Community
: The source-available, free-to-use, and self-managed version of MongoDB:MongoDB的源代码可用、免费使用和自我管理版本
Syntax语法
db.currentOp() has the following form:具有以下形式:
db.currentOp(<operations>)
db.currentOp() can take the following optional argument:可以接受以下可选参数:
operations |
|
Behavior行为
db.currentOp() can accept a filter document or a boolean parameter.可以接受筛选文档或布尔参数。
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:db.currentOp(),则输出仅返回与筛选器匹配的当前操作的信息。筛选文档可以包含:
"$ownOps" |
|
"$all" |
|
<filter> |
|
Passing in 向true to db.currentOp() is equivalent to passing in a document of { "$all": true }. The following operations are equivalent:db.currentOp()传递true相当于传递{ "$all": true }的文档。以下操作是等效的:
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:和数据库分析器报告所有CRUD操作的相同基本诊断信息,包括以下内容:
aggregatecountdeletedistinctfind(OP_QUERYand和command)findAndModifygetMore(OP_GET_MOREand和command)insertmapReduceupdate
These operations are also included in the logging of slow queries. See 这些操作也包含在慢速查询的日志中。有关慢速查询日志记录的更多信息,请参阅slowOpThresholdMs for more information about slow query logging.slowOpThresholdMs。
Access Control访问控制
On systems running with 在authorization, the user must have access that includes the inprog privilege action.authorization运行的系统上,用户必须具有包括inprog权限操作在内的访问权限。
Users can run 即使没有db.currentOp( { "$ownOps": true } ) on mongod instances to view their own operations even without the inprog privilege action.inprog权限操作,用户也可以在mongod实例上运行db.currentOp( { "$ownOps": true } )来查看自己的操作。
Examples示例
The following examples use the 以下示例使用db.currentOp() method with various query documents to filter the output.db.currentOp()方法和各种查询文档来筛选输出。
Write Operations Waiting for a Lock等待锁定的写入操作
The following example returns information on all write operations that are waiting for a lock:以下示例返回等待锁的所有写入操作的信息:
db.currentOp(
{
"waitingForLock" : true,
$or: [
{ "op" : { "$in" : [ "insert", "update", "remove" ] } },
{ "command.findandmodify": { $exists: true } }
]
}
)Active Operations with no Yields无收益的主动操作
The following example returns information on all active running operations that have never yielded:以下示例返回所有从未产生过的活动运行操作的信息:
db.currentOp(
{
"active" : true,
"numYields" : 0,
"waitingForLock" : false
}
)Active Operations on a Specific Database特定数据库上的活动操作
The following example returns information on all active operations for database 以下示例返回运行时间超过3秒的数据库db1 that have been running longer than 3 seconds:db1的所有活动操作的信息:
db.currentOp(
{
"active" : true,
"secs_running" : { "$gt" : 3 },
"ns" : /^db1\./
}
)Active Indexing Operations主动索引操作
The following example returns information on index creation operations on any number of fields:以下示例返回任意数量字段的索引创建操作信息:
db.getSiblingDB("admin").aggregate( [
{ $currentOp : { idleConnections: true } },
{ $match: {
$or: [
{ "op": "command", "command.createIndexes": { $exists: true } },
{ "op": "none", "msg": /^Index Build/ }
]
}
}
] )Output Example输出示例
The following is a prototype of 以下是db.currentOp() output.db.currentOp()输出的原型。
Standalone
The following is a prototype of the 以下是在独立运行时currentOp output when run on a standalone: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>,
"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>
}Replica Set(Primary)
The following is a prototype of the 以下是在副本集的主服务器上运行时currentOp output when run on a primary of a replica set: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>,
"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>
}Sharded Cluster(mongos)
The following is an example of the 以下是在分片集群的currentOp output when run on a mongos of a sharded cluster (Fields may vary depending on the operation being reported):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>,
"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>
}Specific Output Examples具体输出示例
These output samples illustrate 这些输出示例说明了特定操作的当前Op输出。构成实际输出的字段因服务器的角色而异。currentOp output for particular operations. The fields that make up the actual output vary depending on the server's role.
Resharding Output Example重新硬装输出示例
{
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'
}Output Fields输出字段
For a complete list of 有关db.currentOp() output fields, see currentOp.db.currentOp()输出字段的完整列表,请参阅currentOp。