mongodb 批量替換內容的語句


// 注意上面的集合要和下面的集合名稱相同
db.rand_web_test.find(
	{
		'content': /^.*要替換的字符串.*$/
	}
).forEach(
	function (item) {
		var tmp = String(item.content)
		tmp = tmp.replace(/要替換的字符串/g,'替換成字符串')
		if (tmp == null){
				print(item.content)   
		}
		item.content = tmp ;
//		print(tmp)
		print(db.rand_web_test.save(item))
//             db.rand_web_test.save(item)
	}

)

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM