my data:
{
_id: 123,
items: [ { name: "item name", quantity: 1 }, { name: "item name 2", quantity: 1 } ]
}
code:
const doc = await profile.findOne({ _id: 123 })
for (var i = 0 ; i < doc.items.length ; i++) {
doc.items[i].quantity += 1
}
await doc.save()
i tried this but it didn't update the data. Im not using updateOne because i need to call this function like 5-10 times in a for loop, calling await profile.updateOne to update every single item's quantity in the array will make it slower. Im using mongoose btw