Reputation: 21
I have input document list containing AccountID and Amount fields which has repeated AccountID's but with different Amount. How can i form the ouput doclist with only unique AccountID's but the amount summed up?
Ex: InputDocList Doc[0]: AccountID = 111 Amount = 100
Doc[1]: AccountID = 222 Amount = 200
Doc[2]: AccountID = 111 Amount = 300
Doc[3]: AccountID = 222 Amount = 500
OutputDocList should look like: Doc[0]: AccountID = 111 Amount = 400
Doc[1]: AccountID = 222 Amount = 700
Upvotes: 2
Views: 2149
Reputation: 806
I would group the documents by AccountID using pub.document:groupDocuments
. This will give you a group for each unique account ID.
Then for each group, use pub.math:addInt/FloatList
to sum the amounts, and map the result to a new list of {AccountID,totalAmount} documents.
Upvotes: 3