I'm atrying to kill an aggregation operation on a sharded cluster programatically. The operation is launched from Java mongo driver,
The way I've found to kill it is throw a killSessions command with the session identifier.
What I do to properly get the sessions identifier is:
MongoClient mongoClient = ....
mongoClient.startSession()
//call the aggregation stuff..
This thread keeps running, and from another thread, I use the mongoClient object to get the server session and kill it:
BsonDocument serverSession = clientSession.getServerSession().getIdentifier();
BsonBinary value = serverSession.get("id").asBinary();
Then I wrap valueinside a singleton collection of document [{ id: value}] and call $killsessions with this parameter. I run it on top of the mongo admin db.
The result returns me { ok: 1.0 }, but the thread with the operation still keeps running and ends properly on the server The result of the aggregation is written to a new collection on stage $out, so it seems it has no effect on the server session.
How can I kill, programatically, all the operations running on the aggregation? (both client & server side).