I'm trying to update many objects within a nested array when their IDs exist in a list.
The document structure is like so:
{
id: p00,
children: [{
id: c00,
value: true
},
{
id: c01,
value: true
},
{
id: c02,
value: true
}
]
}
I would like to set value=false if id=p00 and children.id in [c00, c01].
This is my attempt, however it's clearly updating making only 1 update to the parent record, meaning only the c00 would be modified with the false value.
collection
.updateMany(and(
eq("id", "p00"),
in("children._id", [c00, c01])),
combine(
set("children.$.value", false)
));
Is this possible, or do I need to move the children up to make a more flatend structure? I'd prefer not to as that introduces it's own problems.
Thanks!