I know this is a very cliche subject, but I feel I’m missing something simple.
This is the DB:
{
"_id" : "66846180e4d8e74d393f4c57",
"name": "GB",
"locations": [
{"name": "GB01", "dateTime": ""},
{"name": "GB02", "dateTime": ""},
{"name": "GB03", "dateTime": ""},
{"name": "GB04", "dateTime": ""},
{"name": "GB04", "dateTime": ""},
{"name": "GB05", "dateTime": ""},
{"name": "GB06", "dateTime": ""},
{"name": "GB07", "dateTime": ""}
]
}
and this is the query:
const result = await Lakes.updateOne(
{
_id:"66846180e4d8e74d393f4c57"
},
{ $set: { "name":name, "locations.$[elem].dateTime": "new dateTime" } },
{
arrayFilters: [
{ "elem.name": "GB01" },
],
}
)
I know the lookup is finding the document, I added the $set for the name to test and it’s updated – I just can’t get the arrayFilters to work. I even normalized the data to simplify the query, but I’m getting no where…If anyone can point out my mistake I’d be very grateful…