I've recently started using mongodb and have been having trouble finding the information I need in the documentation (Maybe I just didn't look in the right places).
Let's say I have two arrays:
ids = [1, 2, 3, 4]
values = [12, 33, 44, 11]
Right now, I'm going through each id in the list and updating the database for every entry, which feels very inefficient:
For this, I'm using an object for each iteration (Here's a simplified example):
update['values']['duration'] = values[i];
This is how I insert into the DB
await CollectionName.updateOne({ids: ids[i]}, {$set: update});
Any suggestions? Thanks! :)
Edit: Example 2:
ids = [4, 7, 9]
values = [
{"array":
"preference" : "test",
"1Duration" : 55,
"2Duration" : 66
},
{"array":
"preference" : "test",
"1Duration" : 22,
"2Duration" : 33
},
{"array":
"preference" : "test",
"1Duration" : 78,
"2Duration" : 11
}
]