Please help me to update an element of the child array in node. I tried this, but it replaced all object.
var assignId = req.body.data.assign_id;
var answer = {
mark: mark,
isCorrect: isCorrect
}
AssignModel.findOneAndUpdate(
{ _id: assignId },
{
$set: {
"answers": answer
}
},
function (err, doc, result) {
if(err) {
return next(err)
}
res.json({
success: true,
result: result
})
});
This is the origin data type in MongoDB.
I want to change the mark of the second object.
But after run the above code, it changed like this.
If you know how to implement that, please help me. Thanks.