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
.
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.
Starting in version 3.6, MongoDB provides $currentOp
aggregation stage. The $currentOp
stage returns a cursor over a stream of documents, each of which reports a single operation. Each operation document is subject to the 16MB BSON limit, but unlike the currentOp
command, there is no limit on the overall size of the result set.
For this reason, the $currentOp
aggregation stage is preferred over the currentOp
command and its mongo
shell helper db.currentOp()
.
db.currentOp()
has the following form:
db.currentOp()
can take the following optional
argument:
operations | boolean or document | Optional. Specifies the operations to report on. Can pass either a boolean or a document:
|
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:
"$ownOps" |
Boolean. If set to On New in version 3.2.9. |
"$all" |
Boolean. If set to 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
and the database profiler report the same basic diagnostic information for all CRUD operations, including the following:
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).
On systems running with authorization
, the user must have access that includes the inprog
privilege action.
Starting in 3.2.9, users can run db.currentOp( { "$ownOps": true }
)
on mongod
instances to view their own operations even without the inprog
privilege action.
See also参阅
The following examples use the db.currentOp()
method with various query documents to filter the output.
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:
Changed in version 3.6.
The following example returns information on index creation operations:
The following is a prototype of db.currentOp()
output.
For a complete list of db.currentOp()
output fields, see currentOp.