How to run db.killOp() using the MongoDB native Node.js driver?

前端 未结 2 1517
我在风中等你
我在风中等你 2021-01-22 08:16

I am using MongoDB native Node.js Driver 1.4.38.

I have got all running operation using :

var maxSecsRunning = 2;
db.collection(\'$cmd.sys.inprog\').fin         


        
2条回答
  •  孤独总比滥情好
    2021-01-22 08:23

    From MongoDB 3.2 onwards, the accepted answer will no longer work, since the system collections are no longer exposed.

    Instead you have a command hash for this operation. This works for me:

    db.command({currentOp:1})
                    .then( result => {
                        if( result && result.inprog ) {
                            result.inprog.forEach( item =>
                            {
                                if( // some condition 
                                  ) {
                                      db.command( {killOp: 1, op: item.opid} );
                                }
                            });
                        }
                    } )
                    .catch( err => {
                        // don't forget to handle errors.
                           );  }  );
    

提交回复
热议问题