I am trying to do following update in mongo, and getting error:
db.xyz.updateOne(
{ "xyzId": 1 },
{
$push: { "packages": { "id": 11 } },
$pull: { "packages.$[pkg10].items": { "id": 1000 } }
},
{
arrayFilters: [{ "pkg10.id": 1 }]
}
)
Error:
{
"message" : "Updating the path 'packages.$[pkg10].items' would create a conflict at 'packages'",
"stack" : "script:1:11",
"name" : "WriteError",
"code" : 40,
"index" : 0
}
My question is why this is not able to first add one package in order and then remove item from another specified package ? And how can I know which kinds of updates can lead this type of error.
Similar Question,(but was not helpful): Updating the path 'x' would create a conflict at 'x'