Hi experts
I have a collection, where I need to upsert only on nested array and not on the document
db.nesteddemo.insertOne({name:“toplevel”,nested:[{id:1,val:“1”,val2:“2”}]})
db.nesteddemo.findOneAndUpdate({_id:ObjectId(“62a6a45bce71e57502b28344”)},{$addToSet:{nested:{id:2,val:2,val2:“2”}}})
db.nesteddemo.updateOne(
{_id:ObjectId(“62a6a45bce71e57502b28344”)},
{ $set: { “nested.$[elem].val” : -1 } },
{ arrayFilters: [ { “elem.id”: 3} ],upsert:true }
)
the above are not working
here if I want to conditionally perform upsert operation on nested field “nested” based on nested.id field
does mongodb support this operation ?