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)