mongo批量删除js示例

db.system.js.save(
    {
        _id: "ddel",
        value :function (x,y,range,sleeptime) {
            try{
                for (var i = x ; i <= y; i +=range){
                    print("delete_id: "+ i);
                    db.getCollection('xxx').deleteMany({"_id":{$gte:i,$lte : i+range}})
                    sleep (sleeptime);
                };
            }

            catch (e) {
                print(e);
            }
        }
    }
)

 

db.loadServerScripts()


ddel(79000,80000)

posted @ 2021-05-28 15:26  剑握在手  阅读(103)  评论(0编辑  收藏  举报
返回顶部↑