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