mongo 批量替换字符串
需求 文档cdr_20201120 中字段 downloadurl 中的 http://172.16.180.71:8093xxxxxxxxxx 批量替换为 http://113.0.31.66:9093xxxxxxxxxx
db.getCollection('cdr_20201120').find({'downloadurl':{'$ne':null}, 'downloadurl':/^http:\/\/172.16.180.71:8093/}).
forEach(
function(item) {
var tmp = String(item.downloadurl)
if (tmp == null){
print(item.downloadurl)
}
else{
tmp = tmp.replace(/^http:\/\/172.16.180.71:8093/g,"http://113.0.31.66:9093");
}
item.downloadurl = tmp ;
db.getCollection('cdr_20201120').save(item);
print("update to " + item.downloadurl)
}
);
posted on 2020-11-20 14:51 QQ10053660 阅读(380) 评论(0) 编辑 收藏 举报