title: 500 Internal Server Error: cannot update user in mongoose
body: <p>I am trying to run a put function to update a user in my mongoDB, but I am getting a 500 Internal Service error. I am using the <a href="https://github.com/angular-fullstack/generator-angular-fullstack" rel="nofollow">angular-fullstack</a> generator</p>
  
  <p>I use this resource in my controller:</p>
  
  <pre><code>  update(User) {
      User.$update();
    }
  </code></pre>
  
  <p>Here are the functions I call in the backend to try and put the data everything seems to be working fine except for when I call saveUpdates, it seems like that is triggering the 500 error.:</p>
  
  <pre><code>function handleError(res, statusCode) {
    statusCode = statusCode || 500;
    return function(err) {
      res.status(statusCode).send(err);
    };
  }
  // this seems to be the function giving me the problem. 
  function saveUpdates(updates) {
    return function(entity) {
      var updated = _.merge(entity, updates);
      return updated.saveAsync()
        .spread(updated =&gt; {
          return updated;
        });
    };
  }
  
  function respondWithResult(res, statusCode) {
    statusCode = statusCode || 200;
    return function(entity) {
      if (entity) {
        res.status(statusCode).json(entity);
      }
    };
  }
  
  function handleEntityNotFound(res) {
    return function(entity) {
      if (!entity) {
        res.status(404).end();
        return null;
      }
      return entity;
    };
  }
  
  export function updateUser(req, res) {
    if (req.body._id) {
      delete req.body._id;
    }
  User.findByIdAndUpdate(req.params.id)
      .then(handleEntityNotFound(res))
      .then(saveUpdates(req.body))
      .then(respondWithResult(res))
      .catch(handleError(res));
      }
  </code></pre>
  
  <p>I have tried following recommendations on <a href="https://github.com/angular-fullstack/generator-angular-fullstack/issues/310" rel="nofollow">this</a> page for angular-full stack, such as changing ._merge to ._extend to no avail. </p>