Мои данные следующие:
{
"_id": {
"$oid": "5e57db66c6bb04eb902589a2"
},
"name": "temp1",
"sub_arr": [{
"_id_": "53",
"_text": "Different ministries & states are working together",
"labels": ["A", "B", "C", "D", "E"]
}, {
"_text": "We need to work together, take small yet important measures to ensure self-protection.",
"_id_": "54",
"labels": ["A", "B", "C", "D", "E", "F"]
}]
}
Я могу получить элемент нужного мне подмассива следующим образом:
db.mycollection.find({"name":"temp1"}, {"sub_arr":{"$elemMatch": {"_id_": "54"}}})
Теперь я хотел бы вставить в этот элемент другой подмассив выглядит следующим образом:
db.mycollection.find({"name":"temp1"}, {"sub_arr":{"$elemMatch": {"_id_": "54"}}}).upsert.updateOne({'ins_labels': [{"id": "a1", "label": "A"}]})
Однако это не работает. Пожалуйста, помогите