I have a collection product. In this collection for all document I have an array refs_fr with an unknown number of elements:
refs_fr :
[{
"typ": "string_a"
"id": "string_a"
"url": "string_a"
"exp": "
},
{
"typ": "string_b"
"id": "string_b"
"url": "string_b"
"exp": "string_b"
},
{
...
},
...
]
My goal is to update element in ref_fr of each documents where fields of the element match a specific value.
Currently my code look like this :
updates = {
"refs_fr.id": ref["newID"],
"refs_fr.typ": ref["newType"],
"refs_fr.url": ref["newURL"],
"refs_fr.exp": ref["newExp"]
}
await db.collection.update_many({"refs_fr.[]": { "$elemMatch": {"id": ref["id"]}}}, {"$set": { "refs_fr."updates} })
It doesn't update my documents, I saw that I should use $[<identifier>] but I struggle with the syntax. Anyone can help me on this point?
Thanks in advance!