score:0

instead of post

  1. use put when you want to modify a singular resource that is already a part of resource collection.

  2. use patch if request updates part of the resource.

score:0

if not using mongoose middleware or validations on the todo model schema. its better to use update() or updatemany() or findbyidandupdate() which essentially delegates the whole query to mongo server.

example with findbyidandupdate() :

const updateobject = {
  team_name: req.body.team_name,
  team_manager: req.body.team_manager,
  department: req.body.department,
  location: req.body.location,
};

//if the properties in req.body are same as the fields to be update use spread syntax below
// const updateobject = {...req.body};
todo.findbyidandupdate(req.params.id, updateobject, { new: true }, function (
  err,
  todo
) {
  if (err) {
    console.error("error occured!", err);
    return;
  }

  console.info("updated object is::", todo);
});

Related Query

More Query from same tag