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":{"storage":{"$map":{"input":"$storage","as":"store","in":{"$cond":[{"$ne":["$$store.location","b"]},"$$store",{"$mergeObjects":["$$store",{"storedFood":{"$getField":{"field":"theFoods","input":{"$reduce":{"input":"$$store.storedFood","initialValue":{"incOne":false,"theFoods":[]},"in":{"$cond":["$$value.incOne",{"incOne":"$$value.incOne","theFoods":{"$concatArrays":["$$value.theFoods",["$$this"]]}},{"$cond":[{"$ne":["$$this.code","bbb"]},{"incOne":"$$value.incOne","theFoods":{"$concatArrays":["$$value.theFoods",["$$this"]]}},{"incOne":true,"theFoods":{"$concatArrays":["$$value.theFoods",[{"$mergeObjects":["$$this",{"weight":{"$add":["$$this.weight",-2]}}]}]]}}]}]}}}}}}]}]}}}}}])

Result