{
"_id": "58fe27e0e340671c9859c995",
"__v": 0,
"form": [
{
"_id": "58fe2b1de437791cd02b9a8c",
"sections": [
{
"_id": "58fe2b1de437791cd02b9a8d",
"input": {
"_type": "radio"
}
}
]
},
{
"_id": "58fe2ca32470711c586d6b6e",
"sections": []
}
]
}
var save = function(req, res) {
var survey = {};
survey.id = req.params.surveyId; // 58fe27e0e340671c9859c995
survey.form_id = req.params.formId; // 58fe2b1de437791cd02b9a8c
survey.newObj = req.body.sections; // [{ input: {_type: 'checkbox'}}]
Survey.update(
{ _id: survey.id }, // 58fe27e0e340671c9859c995
{$set:
{'form': { _id: survey.form_id , sections: survey.newObj } }
},
{safe: true, upsert: true},
function(err, model) {
if (err)
res.send(err);
res.json(model);
}
);
};
I'd like to replace what's inside the entire array of objects ( sections
) with a new array of objects: [{ input: {_type: 'checkbox'}}]
at _id: 58fe2b1de437791cd02b9a8c
My function save is not working.