1. 删除数据前保存到B表
查看在sta表中存在,但不在stb表中存在的记录(带一些条件),
然后我们要删掉stb表中的记录,删除前,保存到一个备份表中。
var rds = db.getCollection("sta”).find({“A”:1})
var sbs=[];
rds.forEach(function(a){
var sb= a.sn;
sbs.push(sb);
})
var rds2 = db.stb.find({“B”:{"$nin":sbs},“tp”:“flag”})
rds2.forEach(function(a){
db.stb_20200521.insert(a)
db.stb.remove({"_id":a._id})
})