Database
[{product:"Mobile Phone",store:"Electronics Store",total_quantity:5,locations:[{id:"loc1",quantity:3},{id:"loc2",quantity:2}]}]
Query
db.collection.aggregate([{$addFields:{total_quantity:{$subtract:["$total_quantity",{$arrayElemAt:["$locations.quantity",{$indexOfArray:["$locations.id","loc1"]}]}]}}},{$addFields:{locations:{$filter:{input:"$locations",cond:{$ne:["$$this.id","loc1"]}}}}}])