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)