Tech C**P
15 subscribers
161 photos
9 videos
59 files
304 links
مدرس و برنامه نویس پایتون و لینوکس @alirezastack
Download Telegram
How to kill a process in mongo shell?

If you are unfamiliar with your current database schema and indexes, or run a heavy query by mistake on production database things go nasty! To find the query and kill it run mongo client as below and run currentOp command:
> mongo
> db.currentOp()

currentOp() database method will display the ongoing queries in json format, find the query which is related to you and get its opid. Now you need
to run killOp() database method to kill that process as below:
db.killOp(229)

229 is the operation id we have got from the first command.

NOTE: terminate running operations with extreme caution. Only use db.killOp() to terminate operations initiated by clients and do not terminate internal database operations.

#mongodb #mongo #killOp #currentOp #query
On previous posts we explained about query slowness. Here we try to explain different parts of the function.

db.currentOp: in progress operations in mongoDB is displayed by this command. The response of the command is in json format, so you
can use command like db.currentOp()['inprog']. The response has many useful informations like lock status, numYields and so on.
The part we are interested in is opid part. opid is the pid number of the query operation. op section of each operation shows the type of the query. It can be an internal database command, insert command and or query. secs_running of the operation is the part that we can check whether a query has taken a long time or not. It is in second.


db.killOp : killing an operation is just as simple as giving the opid number to killOp as below:

db.killOp(6123213)

This is all we've done in previous posts, to kill slow queries in mongoDB.

#mongodb #mongo #currentOp #killOp #opid