In the example below I am updating a simple document but some of the new data will come as undefined since the REST client does not supply new data for it assuming that it only pushes the data it wishes to change.
What happens is that the data for the fields that comes undefined will get overridden, too (I guess this is logical).
What's the strategy about only updating the data that has come without having to do explicit manual checks in the code?
router.patch('/', function (req, res) {
Portfolio.findOneAndUpdate({'_id': req.body._id},
{
name: req.body.name,
isActive: req.body.isActive
},
{upsert: true},
function (err, data) {
if (err) {
return res.status(500).send(err.message);
}
else {
res.status(200).send(data);
}
});
});
via abolotnov
No comments:
Post a Comment