mongoDB自动杀执行时间的连接

####shell 执行
mongo -u'root' -p'密码' admin mg.js


[root@localhost ~]# cat mg.js 
    
 var currOp = db.currentOp(    {     "active" : true,     "secs_running" : { "$gt" : 30 }    } );

    for (op in currOp.inprog) {
        if ("192.168.10.176" == currOp.inprog[op].client.split(":")[0]) 
       {
            db.killOp(currOp.inprog[op].opid)
        }
    }

最后加入定时任务执行

 

 

[root@localhost ~]# cat .mongorc.js
killMyRunningOps = function (clientIp) {

var currOp = db.currentOp( { "active" : true, "secs_running" : { "$gt" : 30 } } );
for (op in currOp.inprog) {
if (clientIp == currOp.inprog[op].client.split(":")[0]) {
db.killOp(currOp.inprog[op].opid)
}
}
}

posted @ 2018-09-06 09:26  滴滴滴  阅读(1052)  评论(0编辑  收藏  举报