Docs 主页 → 开发应用程序 → MongoDB Manual
db.currentOp()
定义
db.currentOp()
返回一个文档,其中包含有关数据库实例正在进行的操作的信息。
db.currentOp()
方法封装数据库命令currentOp
。使用
$currentOp
聚合阶段而不是currentOp
命令及其mongosh
辅助方法db.currentOp()
。注意
从 MongoDB 5开始。 0 ,即
$currentOp
聚合阶段,在使用mongosh
运行辅助方法db.currentOp()
时使用鉴于此,在5中。 0版本的 Shell 和使用 mongosh 时,
db.currentOp()
结果集不受针对先前旧mongo
版本文档的16 MB BSON 文档返回大小限制的约束。
语法
db.currentOp()
采用以下形式:
db.currentOp(<operations>)
db.currentOp()
可以采用以下可选参数:
行为
db.currentOp()
可以接受筛选器文档或布尔参数。
如果将筛选器文档传递给db.currentOp()
,则输出仅返回与筛选器匹配的当前操作的信息。筛选器文档可以包含:
将true
传递给db.currentOp()
相当于传入{ "$all": true }
的文档。以下操作是等效的:
db.currentOp(true) db.currentOp( { "$all": true } )
db.currentOp()
和数据库分析器会为所有 CRUD 操作报告相同的基本诊断信息,其中包括:
getMore
(OP_GET_MORE 和command
)
这些操作也包含在慢查询日志中(有关慢查询日志的更多信息,请参阅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: "none", "msg" : /^Index Build/ } ] } )
输出示例
以下是db.currentOp()
输出的原型。
特定输出示例
这些输出示例说明了特定操作的 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。