Database
[{user:"a",calories:12,meals:[{calories:5,name:"a"},{calories:6,name:"b"}]}]
Query
db.collection.update({user:"a","meals.name":"a"},[{$set:{calories:{$subtract:["$calories",{$reduce:{input:"$meals",initialValue:0,in:{$add:["$$value",{$cond:[{$eq:["$$this.name","a"]},"$$this.calories",0]}]}}}]}}}])