Database

[{_id:ObjectId("5fedda064c9073b6289e8eaf"),storage:[{location:"locA",storedFood:[{"name":"a","code":12,"weight":20},{"name":"b","code":13,"weight":20}]},{location:"locB",storedFood:[{"name":"a","code":12,"weight":20},{"name":"b","code":13,"weight":20}]}]}]

Query

db.collection.update({storage:{$elemMatch:{location:"locA"}}},[{$set:{storage:{$map:{input:"$storage",as:"st",in:{$cond:[{$eq:["$$st.location","locA"]},{location:"$$st.location",storedFood:{$map:{input:"$$st.storedFood",in:{$cond:[{$eq:["$$this.code",12]},{$mergeObjects:["$$this",{weight:{$max:[0,{$subtract:["$$this.weight",15]}]}}]},"$$this"]}}}},"$$st"]}}}}}])

Result