Given the following document inside Mongo:
{
"_id" : ObjectId("5d5e9852b2b803bfc66e74a6"),
"name" : "NAME",
"collection1" : [
{ "type" : "TYPE", "collection2" : [ ] }
]
}
I would like to add elements in the collection2 attribute. I am using the mongo console.
I tried using this query:
db.mycollection.updateOne(
{"name": "NAME"},
{$addToSet: {"collection1.$[element].collection2" : { $each: ["a", "b", "c"]}}},
{arrayFilters: [{element: 0}]}
);
I also tried to use push, but with no success.
The console returns:
{ "acknowledged" : true, "matchedCount" : 1, "modifiedCount" : 0 }