最近想要多集合關聯更新數據;但是mongodb不像關係型數據庫不能直接join查詢,網上查了很多沒找到好辦法,
哪位大神可以分享更好的。
問題:根據A集合中得對應字段來更新集合B中的字段,腳本如下:
//源集合
var mplist = db.A.find({"dq":"北京"});
//更新集合B
mplist.forEach(function(o){
for(var b=db.B.find({"name":o.name}); merchant.hasNext();){
var temp = b.next();
temp.image = o.image;
temp.openTime = o.start;
temp.closeTime = o.end;
db.B.save(temp);
}
});