How to turn an array into an object with summed values?

I just realized my title doesn’t make sense. My bad. Seems I can’t edit. It should be: “How to merge the sum of different documents based on one field value?”