Database
[{"_id":ObjectId("56e9b39c732b6122f878f882"),storage:[{location:"a",storedFood:[{code:"bbb",name:"c",weight:17},{code:"bbb",name:"c",weight:18},{code:"ddd",name:"d",weight:19}]},{location:"b",storedFood:[{code:"bbb",name:"c",weight:56},{code:"bbb",name:"c",weight:4},{code:"ddd",name:"d",weight:191}]}]}]
Query
db.collection.update({_id:ObjectId("56e9b39c732b6122f878f882"),"storage.location":"b"},[{$set:{newItem:{$reduce:{input:{$getField:{input:{$first:{$filter:{input:"$storage",as:"st",cond:{$eq:["$$st.location","b"]}}}},field:"storedFood"}},initialValue:[],in:{$concatArrays:["$$value",{$cond:[{$and:[{$eq:["$$this.code","bbb"]},{$not:{$in:["bbb","$$value.code"]}}]},[{$mergeObjects:["$$this",{weight:{$add:["$$this.weight",-2]}}]}],["$$this"]]}]}}}}},{$set:{storage:{$map:{input:"$storage",in:{$cond:[{$eq:["$$this.location","b"]},{"$mergeObjects":["$$this",{storedFood:"$newItem"}]},"$$this"]}}},newItem:"$$REMOVE"}}])