I am new to moogoose, i am running into the difficult to update object in the db.
here is my shcema.
var FormSchema = new Schema({
formContent : {
type : Object,
required : true
},
formName : String,
createdDateTime : Date
});
Here is the controller to update the field, i have used '[]' and it works to clean up the field, but whenever i PUT a new object and try to replace, and it just stay the same... any idea or suggestion would be much appreciated. stuck in this for hrs...
// Updates an existing form in the DB.
exports.update = function(req, res) {
if(req.body._id) { delete req.body._id; }
Form.findById(req.params.id, function (err, form) {
if (err) { return handleError(res, err); }
if(!form) { return res.send(404); }
var updated = _.merge(form, req.body);
// updated.formContent = [];
updated.save(function (err) {
if (err) { return handleError(res, err); }
return res.json(200, form);
});
});
};