How to run Mongo database db.currentOp(true) command using API
2
votes
2
answers
3390
views
Using the Mongo Java API I can run the currentOp() command like this:
MongoClient mongoClient = null;
mongoClient = new MongoClient( "127.0.0.1", 27017);
db = mongoClient.getDB("admin");
db.command("currentOp");
But I only get details of current operations. I need to get details of idle connections too.
With reference with this
**Behavior**
If you pass in true to db.currentOp(), the method returns information on all operations, including operations on idle connections and system operations.
db.currentOp(true)
Passing in true is equivalent to passing in a query document of { '$all': true }.
If you pass a query document to db.currentOp(), the output returns information only for the current operations that match the query. You can query on the Output Fields. See Examples.
You can also specify { '$all': true } query document to return information on all in-progress operations, including operations on idle connections and system operations. If the query document includes '$all': true as well as other query conditions, only the '$all': true applies.
While using this command
db.command("currentOp(true)");
, I get an exception like this:
> "ok" : 0.0 , "errmsg" : "no such command: 'currentOp(true)', bad cmd: '{ currentOp(true): true }'" , "code" : 59}
Asked by Velkumar
(41 rep)
Mar 9, 2017, 07:30 AM
Last activity: Dec 18, 2019, 02:02 AM
Last activity: Dec 18, 2019, 02:02 AM