mongo 实现替换某个字段中的某个字符的特定字符


 

以下脚本实现将 filepath字段中的 http://116.213.206.162替换成 http://221.122.94.147,例如将“http://116.213.206.162/uncall_api/downloadFile.php?f_path=”替换成

“http://221.122.94.147/uncall_api/downloadFile.php?f_path=”

db.getCollection('callRecord').find({'filepath':{'$ne':null}, 'filepath':/^http:\/\/116.213.206.162/}).
forEach( 
function(item) {
var tmp = String(item.filepath)
//var tmp1 = tmp.match(/^http:\/\/116.213.206.162/)
if (tmp == null){
print(item.filepath) 
}
else{
tmp = tmp.replace(/^http:\/\/116.213.206.162/g,"http://221.122.94.147");
}
item.filepath = tmp ;
db.getCollection('callRecord').save(item);
} 
);

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM