mongo批量替换字符串

2019-10-20  本文已影响0人  chaosii
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);
    } 
);
上一篇 下一篇

猜你喜欢

热点阅读