w3resource

MongoDB: db.currentOp() method

db.currentOp

The db.currentOp() method is used to return a document that contains information on in-progress operations for the database instance.

Syntax:

db.currentOp()

Parameters:

Name Description Required /
Optional
Type
operations Specifies the operations to report on. Can pass either a boolean or a document.
Specify true to include operations on idle connections and system operations. Specify a document with query conditions to report only on operations that match the conditions.
Optional boolean or document

Example: MongoDB: db.currentOp() method

The following example returns information on all operations, including operations on idle connections and system operations.

db.currentOp(true);

Output:

> db.currentOp(true);
{
        "inprog" : [
                {
                        "opid" : 0,
                        "active" : false,
                        "op" : "none",
                        "ns" : "",
                        "query" : {

                        },
                        "desc" : "DataFileSync",
                        "waitingForLock" : false,
                        "numYields" : 0,
                        "lockStats" : {
                                "timeLockedMicros" : {

                                },
                                "timeAcquiringMicros" : {

                                }
                        }
                },
                {
                        "opid" : 7,
                        "active" : false,
                        "op" : "insert",
                        "ns" : "local.startup_log",
                        "insert" : {

                        },
                        "client" : "0.0.0.0:0",
                        "desc" : "initandlisten",
                        "waitingForLock" : false,
                        "numYields" : 0,
                        "lockStats" : {
                                "timeLockedMicros" : {
                                        "R" : NumberLong(0),
                                        "W" : NumberLong(849)
                                },
                                "timeAcquiringMicros" : {

                                }
                        }
                },
                {
                        "opid" : 3,
                        "active" : false,
                        "op" : "none",
                        "ns" : "",
                        "query" : {

                        },
                        "desc" : "clientcursormon",
                        "waitingForLock" : false,
                        "numYields" : 0,
                        "lockStats" : {
                                "timeLockedMicros" : {
                                        "r" : NumberLong(115300),
                                        "w" : NumberLong(0)
                                },
                                "timeAcquiringMicros" : {
                                        "r" : NumberLong(368559),
                                        "w" : NumberLong(0)
                                }
                        }
                },
                {
                        "opid" : 927,
                        "active" : false,
                        "op" : "query",
                        "ns" : "test.system.indexes",
                        "query" : {
                                "expireAfterSeconds" : {
                                        "$exists" : true
                                }
                        },
                        "client" : "0.0.0.0:0",
                        "desc" : "TTLMonitor",
                        "waitingForLock" : false,
                        "numYields" : 0,
                        "lockStats" : {
                                "timeLockedMicros" : {
                                        "r" : NumberLong(45),
                                        "w" : NumberLong(0)
                                },
                                "timeAcquiringMicros" : {
                                        "r" : NumberLong(1),
                                        "w" : NumberLong(0)
                                }
                        }
                },
                {
                        "opid" : 5,
                        "active" : false,
                        "op" : "none",
                        "ns" : "",
                        "query" : {

                        },
                        "desc" : "RangeDeleter",
                        "waitingForLock" : false,
                        "numYields" : 0,
                        "lockStats" : {
                                "timeLockedMicros" : {

                                },
                                "timeAcquiringMicros" : {

                                }
                        }
                },
                {
                        "opid" : 921,
                        "active" : false,
                        "op" : "query",
                        "ns" : "",
                        "query" : {
                                "isMaster" : 1,
                                "forShell" : 1
                        },
                        "client" : "127.0.0.1:50533",
                        "desc" : "conn1",
                        "connectionId" : 1,
                        "waitingForLock" : false,
                        "numYields" : 0,
                        "lockStats" : {
                                "timeLockedMicros" : {

                                },
                                "timeAcquiringMicros" : {

                                }
                        }
                }
        ]
}

Retrieve the restaurants data from here

Previous: db.createCollection() method
Next: db.dropDatabase() method



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/mongodb/shell-methods/database/db-currentOp.php