Sum toLong overflow error

Iā€™m trying to get sum of amounts using a cloud function but I receive overflow error.
Iā€™m using $toLong and the amounts are kept in the database as string

{ā€œcodeā€:141,ā€œerrorā€:ā€œFailed to parse number ā€˜15000000000000000000ā€™ in $convert with no onError value: Overflowā€}

here is the code:

Moralis.Cloud.define(ā€œtotalAmountā€, async (request) => {
let query = new Moralis.Query(ā€œPredictionsBetā€);
const pipeline = [
{group: {objectId: ā€˜$addressā€™, totalAmount:{$sum:{$toLong : ā€˜$amountā€™}}}}
];

const result = query.aggregate(pipeline);
return result;
});

that particular value may be greater than the max value that can be represented on a long variable (64 bits with signed representation: LLONG_MAX Maximum value for a variable of type long long 9223372036854775807)

so is there a way to sum bignumbers?

I donā€™t know if you could do it directly in aggregate, you could do is separately in javascript

thank you. in that case is it possible to overcome 1000 limit? Iā€™m trying to get a volume of last 30 days and it has more than 1000 entries

you can specify a different limit, like using query.limit(1000000)