JavaScript How to update only some properties of object in MongoDB database update only some columns sql,mongoose update only some fields,

My code below doesn't allow the API user to update only one field by passing one request property. I can remove the null at userObj, but the UI developer will have to pass existing data from the database to do an update, which is not the best practice.

Here is my Express route:

router.put('/user', (req, res) => {
  const userObj = {
    name: req.body.name || null,
    location: {
      city: req.body.city || null
      },
      phone: req.body.phone || null
    };

  User.updateUser(req.body.id, userObj)
});

Here is my Mongoose model's updateUser function:

module.exports.updateUser = (_id, userObj, callback) => {
  User.findOneAndUpdate({_id}, userObj, { upsert: true, 'new': true }, callback);
}
Answer:1

I'm using this basic code to hide one block of text and display another and it works well but what do I need to do to have a second click close the text again? Right now it stays open until something ...

I'm using this basic code to hide one block of text and display another and it works well but what do I need to do to have a second click close the text again? Right now it stays open until something ...

  1. javascript display hide
  2. javascript display hide div
  3. javascript display hide element
  4. javascript hide display table row
  5. javascript hide display table column
  6. javascript display show hide
  7. javascript hide display none
  8. javascript display show hide div
  9. javascript style display hide
  10. javascript css display hide
  11. javascript onclick display hide
  12. javascript style display show hide
  13. javascript hide element display none
  14. javascript display hide content

Need help to convert below JSON string into JSON object.Even string JSON is valid json (verified by https://jsonlint.com/). JSON: { "condition": "AND", "rules": [{ "id": "amount"...

Need help to convert below JSON string into JSON object.Even string JSON is valid json (verified by https://jsonlint.com/). JSON: { "condition": "AND", "rules": [{ "id": "amount"...

  1. json.parse not working
  2. json.parse not working in javascript
  3. json.parse doesn't work

I draw many circles with some loops via d3.js var line = d3.svg.line() var r = 1 var svg = d3.select("body").append("svg:svg") .attr("width", 1000) .attr("height",1000) for ( var x=0; x<...

I draw many circles with some loops via d3.js var line = d3.svg.line() var r = 1 var svg = d3.select("body").append("svg:svg") .attr("width", 1000) .attr("height",1000) for ( var x=0; x<...

  1. lenovo smart display update loop

this is my html code : <div> <label for="accompanying_person" class="col-sm-4 col-form-label">Select number of accompanying person</label> <div class="col-sm-8"&...

this is my html code : <div> <label for="accompanying_person" class="col-sm-4 col-form-label">Select number of accompanying person</label> <div class="col-sm-8"&...