Get the running opIds of current user

I’m connected to a DB and I don’t have access to the admin db so I can’t run db.currentOp… Is there a way to get all the operations currently running under my username ?

The operations are run from a python script. Is there a way to get the opId of a given cursor (usually aggregate) while running it ?

cursor = db.coll.aggregate([{....}])
opid = cursor.get_opId() ?????
for record in cursor:
    ...

Hi @RemiJ and welcome to the Community

The below command, would give you the desired operations

db.currentOp( { “$ownOps”: true } )

Please see the db.currentOp() documentation for more information.

Also, using the above command, you would be able to see not all but only your own operations.

Let us know if you have any further questions.

Thanks
Aasawari

1 Like

Thanks @Aasawari
Sorry for the delay.

I’ve just tried this and still get an error :

mongos> db.currentOp({"$ownOps": true})
{
        "ok" : 0,
        "errmsg" : "not authorized on admin to execute command { currentOp: 1.0, $ownOps: true, lsid: { id: UUID(\"6e4e47ae-f332-4b7d-a833-5b7e553c2b92\") }, $clusterTime: { clusterTime: Timestamp(1657525626, 1), signature: { hash: BinData(0, 14CFA2458DE7ED3958CCB9C029CFF80B35C7DCEB), keyId: 7059081335716970499 } }, $db: \"admin\" }",
        "code" : 13,
        "codeName" : "Unauthorized",
        "operationTime" : Timestamp(1657525846, 3),
        "$clusterTime" : {
                "clusterTime" : Timestamp(1657525846, 3),
                "signature" : {
                        "hash" : BinData(0,"ZXgJ23Ls2/uc3m9GA2tJM/XqhXA="),
                        "keyId" : NumberLong("7059081335716970499")
                }
        }
}

mongodb V4.2.20

user have R+W access to the db where the data are, nothing on any other db.

Documentation is about calling currentOp on mongod. I’m running a sharded db so I don’t know anything about mongod, only mongos. I need a consolidated view of the operations running under my username.