I’m trying to use the pipline/aggregate with mongoDb to sum the total of some transfers in WEI for a ERC20 token on our dApp. I can get the pipline working correctly, but the toLong convertion for the field amount in the database throws an error. Screenshots follow.
const query = new Parse.Query("RenTransfers");
const pipeline = [
{match:{subtract:true} },
{limit:100},
{ group: { objectId: '$owner', sumOftx: { $sum: {$toLong: "$amount"} }}},
];
const ownerCount = await query.aggregate(pipeline, { useMasterKey: true })
console.log(ownerCount)
Note it did not let me post a second screenshot, but i wanted to show that that the field “amount” was a string with a large number.