Hi all, I’m having a problem trying to update a value inside a sub-sub array. The element URLPDF is inside the contratos array and contratos is inside the report array. So my react query is:
updateOne(
{ "report.contratos.NumContrato": `${param[1]}` },
{
$set: {
"report.$.contratos.URLPDF": {
$cond: {
if: {
$eq: ["$report.$.contratos.NumContrato", `${param[1]}`]
},
then: `${param[2]}`,
else: null
}
}
}
}
)
I’m trying to use cond so only one specific element of the subarray is updated and not all the elements. the query is returning an error: unhandledRejection:
MongoServerError: Cannot create field 'URLPDF' in element
If I only leave:
updateOne(
{ "report.contratos.NumContrato": `${param[1]}` },
{
$set: { "report.$.contratos.URLPDF": `${param[1]}` }
}
)
Then all the 10 elements in the subarray are updated with the new value and I don’t want that, I just want to update the one matching the initial seach condition. I haven’t found much about updating in nested array having subarrays.
Please can somebody point me to the right direction.
Thanks