我爱编程

mongodb 批量更新

2018-02-09  本文已影响0人  扎哈_
var a = db.test1.aggregate([
    {$project : 
        {searchText : "$searchText", userId : "$userId"}
        }
])
for(var i = 0; i < a._batch.length; i++){
    db.test2.update({ _id : ObjectId(a._batch[i].userId)}, {$set : { "searchText" : a._batch[i].searchText }})
}

这只是一种方式吧,也可以先获取Id数组,然后用in更新

上一篇 下一篇

猜你喜欢

热点阅读