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);
})
本文来自博客园,作者:鲤鱼洲畔,转载请注明原文链接:https://www.cnblogs.com/liyuzhoupan/p/16626738.html