I'm not sure if there are direct API methods either, but like most mongo operations these really just function by making similar wire protocol operations to "system collections" as it were.
So the methods for finding and cancelling are documented under db.currentOp()
and db.killOp()
. Those these are the shell implementation methods all they are doing id accessing the "system collections" underneath, being $cmd.sys.inprog
and $cmd.sys.killop
respectively.
Specifically their shell implementations are:
currentOp:
function ( arg ){
var q = {}
if ( arg ) {
if ( typeof( arg ) == "object" )
Object.extend( q , arg );
else if ( arg )
q["$all"] = true;
}
return this.$cmd.sys.inprog.findOne( q );
}
killOp:
function (op) {
if( !op )
throw "no opNum to kill specified";
return this.$cmd.sys.killop.findOne({'op':op});
}
This makes a simple translation in to Java code, so for instance, after determining the current operation number for the operation you wish to halt, you just issue a query as follows ( forgiving my quick cut and paste from existing Sprint data code, so whatever actual method to get the collection object ):
DBCollection collection = mongoOperation.getCollection("$cmd.sys.killop");
BasicDBObject query = new BasicDBObject("op", opNumber);
DBObject result = collection.findOne(query);
That's the basics of it. See the documentation resources listed for more information on how to match which operation you want to cancel.