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)
	}

)

  

posted @ 2019-09-23 16:52  百猎  阅读(2657)  评论(0编辑  收藏  举报