我有输入文档列表,其中包含AccountID和Amount字段,这些字段重复了AccountID,但具有不同的金额。我如何使用唯一的AccountID来形成ouput doclist,但总结的数量是多少?
Ex:InputDocList Doc [0]:AccountID = 111 金额= 100
Doc [1]:AccountID = 222 金额= 200
Doc [2]:AccountID = 111 金额= 300
Doc [3]:AccountID = 222 金额= 500
OutputDocList应如下所示: Doc [0]:AccountID = 111 金额= 400
Doc [1]:AccountID = 222 金额= 700
答案 0 :(得分:3)
我会使用pub.document:groupDocuments
按AccountID对文档进行分组。这将为您提供每个唯一帐户ID的组。
然后,对于每个组,使用pub.math:addInt/FloatList
对金额求和,并将结果映射到 {AccountID,totalAmount} 文档的新列表。