Lodash merge with mongoose
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
.
exports.update = function(req, res) { if(req.body._id) { delete req.body._id; } Entity.findById(req.params.id, function (err, entity) { if (err) { return handleError(res, err); } if(!entity) { return res.send(404); } _.extend(entity, req.body); entity.save(function (err) { if (err) { return handleError(res, err); } return res.json(200, entity); }); });};