On this page本页内容
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
.db.currentOp()
方法包装数据库命令currentOp
。
Note
Because 由于currentOp
command and db.currentOp()
helper returns the results in a single document, the total size of the currentOp
result set is subject to the maximum 16MB BSON size limit for documents.currentOp
命令和db.currentOp()
助手在单个文档中返回结果,因此currentOp
结果集的总大小受文档的最大16MB BSON大小限制的约束。
Starting in version 3.6, MongoDB provides 从3.6版开始,MongoDB提供了$currentOp
aggregation stage. $currentOp
聚合阶段。The $currentOp
stage returns a cursor over a stream of documents, each of which reports a single operation. $currentOp
阶段返回一个游标到一个文档流上,每个文档都报告一个操作。Each operation document is subject to the 16MB BSON limit, but unlike the 每个操作文档都受16MB BSON限制,但与currentOp
command, there is no limit on the overall size of the result set.currentOp
命令不同,结果集的总体大小没有限制。
For this reason, the 因此,$currentOp
aggregation stage is preferred over the currentOp
command and its mongo
shell helper db.currentOp()
.$currentOp
聚合阶段优于currentOp
命令及其mongo
shell助手db.currentOp()
。
db.currentOp()
has the following form:具有以下形式:
db.currentOp()
can take the following optional argument:可以采用以下可选参数:
operations | boolean |
|
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. db.currentOp()
,则输出仅返回与筛选器匹配的当前操作的信息。The filter document can contain:筛选文档可以包含:
"$ownOps" |
|
"$all" |
|
<filter> |
|
Passing in 对true
to db.currentOp()
is equivalent to passing in a document of { "$all": true }
. db.currentOp()
传入true
相当于传入一个{ "$all": true }
的文档。The following operations are equivalent:以下操作是等效的:
db.currentOp
and the database profiler report the same basic diagnostic information for all CRUD operations, including the following:以及数据库探查器为所有CRUD操作报告相同的基本诊断信息,包括:
aggregate
count
delete
distinct
find
(OP_QUERY and command
)findAndModify
getMore
(OP_GET_MORE and command
)insert
mapReduce
update
These operations are also included in the logging of slow queries (see 这些操作也包括在慢速查询的日志记录中(有关慢速查询日志记录的更多信息,请参阅slowOpThresholdMs
for more information about slow query logging).slowOpThresholdMs
)。
On systems running with 在使用authorization
, the user must have access that includes the inprog
privilege action.authorization
运行的系统上,用户必须具有包括inprog
权限操作的访问权限。
Starting in 3.2.9, users can run 从3.2.9开始,用户可以在db.currentOp( { "$ownOps": true } )
on mongod
instances to view their own operations even without the inprog
privilege action.mongod
实例上运行db.currentOp( { "$ownOps": true } )
,以查看自己的操作,即使没有inprog
权限操作。
The following examples use the 以下示例将db.currentOp()
method with various query documents to filter the output.db.currentOp()
方法与各种查询文档一起使用,以筛选输出。
Changed in version 3.6.在版本3.6中更改。
The following example returns information on all write operations that are waiting for a lock:以下示例返回有关等待锁定的所有写入操作的信息:
The following example returns information on all active running operations that have never yielded:下面的示例返回有关所有从未生成的活动运行操作的信息:
The following example returns information on all active operations for database 以下示例返回数据库db1
that have been running longer than 3 seconds:db1
的所有活动操作的信息,这些操作已运行超过3秒:
Changed in version 3.6.已在3.6版中更改。
The following example returns information on index creation operations:以下示例返回有关索引创建操作的信息:
The following is a prototype of 以下是db.currentOp()
output.db.currentOp()
输出的原型。
For a complete list of 有关db.currentOp()
output fields, see currentOp.db.currentOp()
输出字段的完整列表,请参阅currentOp
。