Fondamentalement, vous avez besoin de bulkWrite
opération avec upsert
const array = [
{ someId: 1, someProp: prop1, isOpen: true },
{ someId: 2, someProp: prop1, isOpen: true },
{ someId: 5, someProp: prop1, isOpen: true },
{ someId: 6, someProp: prop1, isOpen: true }
]
Model.bulkWrite(
array.map((data) =>
({
updateOne: {
filter: { someId: data.someId },
update: { $set: { isOpen: false, someProp: data.someProp } },
upsert: true
}
})
)
})
Vous donnera la sortie
[
{ someId: 1, someProp: prop1, isOpen: false },
{ someId: 2, someProp: prop1, isOpen: false },
{ someId: 3, someProp: prop1, isOpen: true },
{ someId: 4, someProp: prop1, isOpen: true },
{ someId: 5, someProp: prop1, isOpen: true },
{ someId: 6, someProp: prop1, isOpen: true }
]