Get the App
SLTechnology News&Howtos  ›  Database  › 

MongoDB to view the current operation db.currentOp ()

Shulou Source: shulou.com Published: 2022-06-01 21:11:37 09月17日 Update

MongoDB to view the current operation db.currentOp ()

Define

Db.currentOp ()

Returns the document of the operation information running on the database instance.

The db.currentOp () method has the following format:

Db.currentOp ()

The db.currentOp () method can use the following optional parameters:

Parameter type description

Operations Boolean value or document is optional. Specifies the action for the report. You can enter a Boolean value or a document.

Specifies the true, including idle connections and system operations.

Specify documents with query criteria and report only actions that match the criteria.

Behavior

If true is passed to db.currentOp (), the method returns information about all operations, including idle connections and system operations.

Db.currentOp (true)

Passing true is equivalent to passing a query document {'$all': true}.

If you pass a query document to db.currentOp (), only the current action that matches the query criteria is returned.

You can also specify that {'$all: true} query documents return information about all running operations, including idle connections and system operations. If

The query document includes'$all':true and other query criteria, and only'$all':true'is applied.

access control

To run user authorization authentication on the system, the user must have access to the inprog behavior.

Example

The following example uses the db.currentOp () method with different query documents to filter the output.

Write operation waiting for lock

The following example returns all write information that is waiting for a lock:

Db.currentOp ({"waitingForLock": true, $or: [{"op": {"$in": ["insert", "update", "remove"]}}, {"query.findandmodify": {$exists: true}}]})

There is no active operation for Yields

The following example returns information about all active operations that are running without Yields:

Db.currentOp ({"active": true, "numYields": 0, "waitingForLock": false})

Active operations for a specific database

The following example returns all active operations that take more than 3 seconds to run for the database db1:

Db.currentOp ({"active": true, "secs_running": {"$gt": 3}, "ns": / ^ db1\. /})

Active index operation

The following example returns information about the index creation operation:

Db.currentOp ({$or: [{op: "query", "query.createIndexes": {$exists: true}}, {op: "insert", ns: / / .system\ .resume\ b /}]})

See: https://docs.mongodb.org/manual/reference/method/db.currentOp/

Tags: Documents queries information examples facets activities runs methods conditions ongoing systems data databases free parameters Boolean reports users indexes behaviors Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple NVidia Shulou Information MariaDB OPPO Reno