Skip to content

fixing generator endpoint exports.update save function #310

@unoriginalscreenname

Description

@unoriginalscreenname

I ran into an issue where doing a put to my endpoint resulted in mongoose returning:

TypeError: Object #<Object> has no method 'save'

I was able to fix this by changing _.merge to _.extend, then calling save directly on the results returned by findById instead of the variable "updated".

Not sure if anybody else was having this issue, but here is what i did.

// Updates an existing list in the DB.
exports.update = function(req, res) {
  if(req.body._id) { delete req.body._id; }

  List.findById(req.params.id, function (err, list) {
    if (err) { return handleError(err); }
    if(!list) { return res.send(404); }

    // var updated = _.merge(list, req.body);

    _.extend(list, req.body);

    //changed from updated to 'list'
    list.save(function (err) {
      if (err) { return handleError(err); }
      return res.json(200, list);
    });
  });
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions