toLong doesnt seem to work

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.

Update: toLong works when I try other numbers or fields. how else can I convert a string to use for the sum function?

This issue has been solved with Moralis Nitro

Moralis Nitro creates an extra column for all the wei strings where the value is stored as NumberLong also

Which server version are you using?

Can you create a new server with latest version and see if it works for you?

Thanks Ivan, big fan of your work. Will i have to migrate all my data to the new server? Its already in production.

https://btx7uykjbmv4.usemoralis.com:2053/server
0.0.337
Mainnet

Appreciate it :raised_hands: we can help you migrate but please first try the new version by creating a new server and see if it solves your issues

In the new version you should see extra columns in the event tables with decimal numbers

ok going to try it now and get back to you. I guess I will have to set up atleast one sync to test it first.

I set up a new nitro server and added the sync for my contact but the table/Class is not showing up in the Browser

on what chain did you try to add that event sync? can you also share the server url?

Eth. https://8vjltfmbhcn7.usemoralis.com:2053/server

can you try again now with that event?

I added the event, the table is working. No tx’s yet, I guess it will take a bit of time to sync the historical?

yes, it could take 1 minute and it will be fast after that

Its syncing. and my toLong problem us also solved. So I need to migrate to this? And also upgrade to the $200 per month package that I was paying on the old server.

Before we migrate - can you ensure you are not using any of the breaking changes here Moralis nitro is out! 🚀

1 Like

confirming that there are no breaking changes

How long will the migration take? Want to just plan around it. Thanks again.

All new created servers are nitro servers now, old servers are still having that nftOwners table. I don’t know how much time the transition will take.

We can migrate your server in 15 minutes
But it’s a bit manual process we need to do

Let’s continue in discord so we can create a group

Can you write in this channel in Moralis DAO discord?

Roger, will do right now. Thanks Ivan.