美文网首页我爱编程
mongodb 批量更新

mongodb 批量更新

作者: 扎哈_ | 来源:发表于2018-02-09 16:46 被阅读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更新

    相关文章

      网友评论

        本文标题:mongodb 批量更新

        本文链接:https://www.haomeiwen.com/subject/epfqtftx.html