Home > Blockchain >  How to filter slow query using pymongo?
How to filter slow query using pymongo?

Time:03-22

I'm trying to get slow queries (secs_running >= 5s) via pymongo. I know how to list currentOp:

client = pymongo.MongoClient('mongodb://<IP>:<Port>')
db = client.admin
op_list = db.command("currentOp")

How can I execute the below mongo query from pymongo?

db.currentOP({"secs_running":{"$gte":5}})

I have tryed to execute the below code, but it doesn't seem to work.

op_list = db.command("currentOp",{'secs_running':{'$gte':5}})

Please help, thanks!

CodePudding user response:

You're close, the sytnax you need is:

op_list = db.command({'currentOp': True, 'secs_running': {'$gte': 5}})

Reference: https://docs.mongodb.com/manual/reference/command/currentOp/#mongodb-dbcommand-dbcmd.currentOp

  • Related