Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Find and (safely) kill long running MongoDB queries
var maxSecsRunning = 600;
var dryRun = true;
var currOp = db.currentOp();
for (var oper in currOp.inprog) {
var op = currOp.inprog[oper-0];
if (op.secs_running > maxSecsRunning && op.op == "command" ) {
print("Killing opId: " + op.opid
+ " running for over secs: "
+ op.secs_running
);
if(!dryRun) {
db.killOp(op.opid);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment