mongodbHow to kill an operation in MongoDB?
To kill an operation in MongoDB, you can use the db.killOp()
method. This method takes a single parameter, the operation ID, which can be obtained from the db.currentOp()
method.
Example
> db.currentOp()
{
"inprog" : [
{
"opid" : NumberLong(123456789),
"active" : true,
"secs_running" : NumberLong(123),
"op" : "query",
"ns" : "mydb.mycollection",
"query" : {
"find" : "mycollection"
},
"client" : "127.0.0.1:12345",
"desc" : "conn12345",
"threadId" : "123456789",
"connectionId" : 12345,
"locks" : {
"^" : "W"
},
"waitingForLock" : false,
"numYields" : 0,
"lockStats" : {
"timeLockedMicros" : {
"r" : NumberLong(12345),
"w" : NumberLong(12345)
},
"timeAcquiringMicros" : {
"r" : NumberLong(12345),
"w" : NumberLong(12345)
}
}
}
]
}
To kill the operation with the ID 123456789
, you can use the following command:
> db.killOp(123456789)
{ "info" : "attempting to kill op", "ok" : 1 }
The db.killOp()
method takes a single parameter, the operation ID, which can be obtained from the db.currentOp()
method. The db.currentOp()
method returns a list of operations currently running on the server, including the operation ID, the type of operation, the namespace, the query, and other information. The db.killOp()
method then takes the operation ID and attempts to kill the operation.
Helpful links
More of Mongodb
- How to work with time series data in MongoDB?
- How to check the version of MongoDB?
- How to use watch in MongoDB?
- How to update an array element in MongoDB?
- How to use unwind in MongoDB?
- How to use triggers in MongoDB?
- How to update many documents in MongoDB?
- How to use transactions in MongoDB?
- How to rename a field in MongoDB?
- How to select specific fields in MongoDB query?
See more codes...