The user has the option of updating any of a few values - however, if he only passes in { name: "new name" }
, the email and password fields are also updated but to "null".
How can I only update the fields that are actually provided in req.body, leaving the rest as they are?
This is while still specifying which fields can be updated with a POST request - I've avoided just passing in req.body because I'd like to limit this.
My code looks like:
db.User.findOneAndUpdate({_id: req.params.id}, {
name: req.body.name,
email: req.body.emaill,
password: req.body.password
})
Using something like name: req.body.name && req.body.name
to check if a value is not undefined also overwrites with "null".
Thanks!