Hi!
I’m trying to write a small async function in mongocxx driver that empties some collections using delete_many
.
I also want to have the option to abort the operation while its running.
I came across $currentOp
aggregation and db.killOp()
and it seem to work pretty fine when I test it from the mongos shell, meaning I’m able to catch the delete_many
operation using the following query:
mongos> db.aggregate([ { $currentOp : { allUsers: true } }, { $match : {op: 'remove'} } ])
On the other, when I try the same from the c++ program, I get an empty cursor when trying to $match
only "remove"
operations (when I remove $match
then it does print some documents but not what I was looking for).
These are the few lines of codes in c++ (they don’t print anything with the $match
clause):
MongoClient client1{""};
std::thread{cleanAccountFunc, &client1.conn, accountId}.detach();
MongoClient client2{""};
mongocxx::database db = client2.conn["admin"];
mongocxx::pipeline p{};
p.current_op(make_document(kvp("allUsers", true)));
p.match(make_document(kvp("op", "remove")));
auto cursor = db.aggregate(p, mongocxx::options::aggregate{});
for (auto doc : cursor) {
std::cout << bsoncxx::to_json(doc) << "\n";
}
I am using mongo 5.0.9 version and mongocxx 3.6.6 version.
Am I using it wrong? didn’t find any example for current_op, but from the documentation it seems correct.