I am trying to sum values from different objects. Each object has its ID, but the IDs can repeat in some objects. What I need to do now is sum the values from the objects that have the same ID.
Does someone have an idea for me? I tried to use mongoose aggregate, but with no success.
Let's suppose I have the objects below.
const array = [
{ _id: "123456", value: 30 },
{ _id: "123456789123456789", value: 12 },
{ _id: "123456", value: 25 },
];
I would need something that brings up the following result:
==> id: 123456
value: 55
==> id: 123456789123456789
value: 12