Trying to update an object in an array.
My code:
module.exports = (req, res) => {
var givenProject = req.body;
var query = mongoose.model('cv').findOne({alias: req.params.alias});
query.exec(function(err, cv){
if(err){
res.status(400).send({message: 'Could not find cv with alias: ' + req.params.alias, err: err})
}
var doc = cv.projects.id(req.params.id);
doc.langTitles = givenProject.langTitles;
doc.langDescriptions = givenProject.langDescriptions;
doc.save(function(err){
if(err){
res.status(400).send({message: 'Could not update project', err: err});
return;
}
res.status(200).send();
});
});
};
No error is given. var doc is found and the posted data have the same data structure as doc and it differs from the original.
The doc is not updated. What am I missing here?
var doc = cv.projects.id(req.params.id);? What iscv.projects? Iscv.projects.ida function?