I have the mongodb containing documents in format
{
"name": "device_name",
"LAN": [
{
"MAC": "00-14-22-01-23-45",
"IP": "192.168.1.10",
},
{
"MAC": "00:25:96:FF:FE:12:34:56",
"IP": "192.168.1.54",
}
],
"otherdata": "somedata",
}
I need a function that will get an array of structs corresponding to those documents, get the list of mac-addresses of those structs and upsert the data in db, i.e. if there is a document in db in which LAN contains object with MAC from list of mac-addresses - update "otherdata", otherwise just create new document. The problem is i have multiple mac addresses as input, so I need to use in$. Since new data is specific for each document I need to know what i`m updating at the moment.
As I see it, I need to iterate over mac-addresses and make separate upsert request for each of them, which doesnt seem to be efficient. Is there any other way to do it?