I am new to mongodb so i do not understand how should i update 2 different arrays with one query.
My document look like this –
{
"_id": { "$oid": "663a4dbb97674691089c835a"},
"quantity": [
{
"storage": "GODOWN",
"qty": 0,
"_id": { "$oid": "663a4dbb97674691089c835b"}
},
{
"storage": "STORE",
"qty": 0,
"_id": { "$oid": "663a4dbb97674691089c835c"}
}
],
"pricing": [],
}
Update Query
const PricingCreated = await Item.findOneAndUpdate(
{ _id: entry.itemID, 'quantity._id': entry.storageID },
{ $addToSet:
{
"pricing":
[{ "firstAddedDate": today, mrp: entry.mrp, price: entry.price, qty: entry.qty }]
}
},
{ $inc: { 'quantity.$.qty': entry.qty })
.session(session)