var id = req.params.id;
var updatedDevice = req.body;
Device.update({ _id: id}, updatedDevice, function(err, device) {
if (!err) {
return res.send(device);
} else {
return console.log(err);
}
});
这一次突破“Mod on _id not allowed”
User.findById(req.params.id, function (err, user) { user.activated = req.body.activated; user.role = req.body.role; user.save(function(err, user) { if (!err) { return res.send(user); } else { return console.log(err); } }); });
在这个中我不能像这样添加完整的对象:
//user.activated = req.body.activated;
//user.role = req.body.role;
user = req.body;
user.save(function(err, user) {...
会出现保存错误:(
你可以告诉我最好的方式:D答案 0 :(得分:2)
您必须从更新对象中删除_id
属性:
var updatedDevice = req.body;
delete req.body._id;