mongdb表数据如下:
{
"XH": 1,
"NAME" : "XIE",
"VALUE" : 23
},
{
"XH": 2,
"NAME" : "XLE",
"VALUE" : 24
},
{
"XH": 3,
"NAME" : "XIE",
"VALUE" : 25
}
把数据中NAME为XLE的替换为XIE
db.collection.find({"NAME":"XLE"}).forEach(
function(item) {
var xh = item.XH
var name = String(item.NAME)
name = name.replace('XLE','XIE')
db.collection.update({"XH": xh},{$set:{'NAME':name}});
}
);