返回顶部
扶摇直上九万里,展翅高飞岂可待。

1. mongodb基础:cursor.forEach使用

mongosh下载地址:

https://downloads.mongodb.com/compass/mongodb-mongosh-shared-openssl3-1.6.0.x86_64.rpm?_ga=2.240042379.982442877.1667355362-954946077.1667355362

mongotools下载地址:

https://www.mongodb.com/try/download/database-tools

 

var xtdb_db = connect("ip:port/实例名").getSisterDB("xtdb");
var back_db = connect("ip:port/实例名").getSisterDB("xtdb_del_back");

xtdb_db.auth("username","password");

back_db.auth("username","password");


var cursor = back_db.T_GroupMessage_Bak_202209.find({"_id":{$gte:ObjectId("5d19d616ef2e204a21754958")}});

var x = 0;
cursor.forEach(function(obj){
x++;
if((x%1000) == 0){
sleep(2000);
}

var id = obj._id;
xtdb_db.T_GroupMessage.deleteOne(
{"_id":id}
)
printjson("T_GroupMessage_Bak_202209:" + id);
})


x = 0;
cursor = back_db.T_Message_Bak_202209.find({"_id":{$gte:"5d19d616bd8c47879d186928"}});
cursor.forEach(function(obj){
x++;
if((x%1000) == 0){
sleep(2000);
}

var id = obj._id;
xtdb_db.T_Message.deleteOne(
{"_id":id}
)
printjson("T_Message_Bak_202209:" + id);
})

posted @ 2022-08-26 10:30  鲤鱼洲畔  阅读(73)  评论(0编辑  收藏  举报