美文网首页
mongo批量替换字符串

mongo批量替换字符串

作者: chaosii | 来源:发表于2019-10-20 17:32 被阅读0次
db.getCollection('plugin').find({"des":{"$regex":/.*从其他市场获取.*/}}).
forEach( 
    function(item) {
        var tmp = String(item.des)
        if (tmp == null){
            print(item.des) 
        }
        else{
            tmp = tmp.replace(/从其他市场获取/g,"由用户上传");
        }
        item.des = tmp;
        db.getCollection('plugin').save(item);
    } 
);

db.getCollection('static_game_detail').find({"remind":{"$regex":/.*其他市场获取.*/}}).
forEach( 
    function(item) {
        var tmp = String(item.remind)
        if (tmp == null){
            print(item.remind) 
        }
        else{
            tmp = tmp.replace(/从其他市场获取/g,"由用户上传");
        }
        item.remind = tmp;
        db.getCollection('static_game_detail').save(item);
    } 
);

db.getCollection('static_game_detail').find({"tips.content":{"$regex":/.*其他市场获取.*/}}).
forEach( 
    function(item) {
        var tmp = String(item.tips.content)
        if (tmp == null){
            print(item.tips.content) 
        }
        else{
            tmp = tmp.replace(/从其他市场获取/g,"由用户上传");
        }
        item.tips.content = tmp;
        db.getCollection('static_game_detail').save(item);
    } 
);

相关文章

网友评论

      本文标题:mongo批量替换字符串

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