In the database there is one document with an array history and inside that array 3 nested documents (objects) with a property “name” and a property “status”. 2 of these 3 documents (objects) have a value false for the status property.
This is the NodeJS code that is executed to update the document:
Schema.invoiceModel.updateOne({id: req.params.id},
// mogelijks gebeurt toch automatisch een insert!!!
{
$set:
{
"history.$[elem].status": true
}
}
, {
arrayFilters: [
{"elem.name": "voorschot betaald op"}
]
}).then(result => {
res.status(201).json(
)
}).catch(err => {
console.log(err)
res.status(500).json({
error: err.errors
})
})
Why the document doesn’t update? The values of the status stays on false instead of becoming true…