-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Description
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);
});
});
};