Hi, I have a database trigger that watches for a change in the cancelation status and then go to another collection to update that same field. The trigger is working and the console.log is giving me the updated document but when I query the collection to see if the document was updated the information is not change.
This is the first time I create a database trigger so I followed the snippet example to configure it.
The document field that I want to update is inside an object that is inside in a subarray. The schema is:
"report": [
{
"contract": [
{
"latestVersion": {
"Client": "company name",
"cancelation": {
"updated": {
"$date": {
"$numberLong": "1641814200000"
}
},
"status": true
},
"consecutive": "WRF-X-7786",
}
So what I’m doing is:
return cancelStatus.aggregate([
{
'$unwind': {
'path': '$report'
}
}, {
'$unwind': {
'path': '$report.contract'
}
}, {
'$unwind': {
'path': '$report.contratos.latestVersion'
}
}, {
'$match': {
'report.contratos.consecutive': <consecutive updated>
}
}, {
'$set': {
'report.contract.latestVersion.cancelation.updated': <new datetime>,
'report.contract.latestVersion.cancelation.status': <new status>
}
}
]).next()
.then(updateCancel => {
console.log("Cancelation updated: " + JSON.stringify(updateCancel));
})
.catch(err => console.error("Failed to update cancelation status:", err));
I check the aggregation query in Compass and it works, also the console log gives me an succesful transaction, but the document is not updated and keeps the old values.
Can somebody please help me to understand where might be the error?