Updating nested array of objects using $addToSet

Thanks @Prasad_Saya, arrayFilters did the trick. The following query works for anyone who runs into this issue:

db.collection.update({  _id: "1234567890" }, 
{ $addToSet: { "groups.$[elem].votes": { //new object data } },
{ arrayFilters: [ { "elem.userId": "123" } ] } )
2 Likes