MongoDB字段值批量替换

MongoDB字段值批量替换。比如,将thirdDevID中的123全部替换为456.

db.devices.find({'gateway':"123"}).forEach(function(dev) {
    dev.thirdDevID = dev.thirdDevID.replace('123', '456');
    db.thirdPartyDevices.update({"_id":dev._id},{"$set":{"gateway":"456", "thirdDevID":dev.thirdDevID}});
})

你可能感兴趣的:(MongoDB字段值批量替换)