I have a document like this one:
{
_id:ObjectId('111'),
products:[
{
_id:ObjectId('aaa'),
quantity:2,
price:800
}
]
}
I want to update price field by multiplying it with quantity field ie (2 * 800) of which the result gets updated/assigned to price. (as for this example price gets updated to 1600).
Document after Update :
{
_id:ObjectId('111'),
products:[
{
_id:ObjectId('aaa'),
quantity:2,
price:1600 //the updated field by multiplying the initial 800 * 2
}
]
}
My query for selecting is like this below:
Shop.findOneAndUpdate(
{ "_id": '111, "products._id": 'aaa' }
)
How can I achieve this?