Sum toLong overflow error – Moralis

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;

Read more here: Source link