Question

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

    }   

});

this one break with "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);

              }   

          });

});

In this one i can't add the complete object like this:

//user.activated = req.body.activated;
//user.role = req.body.role;
user = req.body;
user.save(function(err, user) {...

there will be an save error :(

can you show me the best way please :D

Was it helpful?

Solution

You must remove the _id property from your update object:

var updatedDevice = req.body;
delete req.body._id;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top