MongoDB Database Values


i have quite an interesting questions about the Database.
Lets take the “BscTokenTransfer” class as an example.

Is it fixed how it fills? (as it fills automatically as i can see)… or is it changeable?

To be specific… i would like to have the USD value of that buy/sell/transfer in that database.

Is that possible anyhow?

thx for the help

You can use an afterSave hook and add that value in a new column. Or you can use a job that runs every x minutes that does that processing.

The initial data is fixed, you can use hooks to add more info. Don’t try to modify current columns.

1 Like

yeah i just found that out… damn moralis is really one of the best things for the cryptoworld!

Thx for the help, definitly will use that :slight_smile:

1 Like

hi, is there anything i have to be aware of if i add a custom column? i added one to BscTokenTransfers, but if i do a query for example the column is not shown. and if i try to update it, its not updated.

How did you add it? What you mean by is now shown?

You have to add it in dashboard interface

so i went to the dashboard, selected “BscTokenTransfers” clicked on “add a new column” type string, name usdval, and finally added it.

Did also restart the server, just to be sure.

So once the cloudfunction is running, i am doing some debug. first here the current coding just using for testing the functions to learn:

Moralis.Cloud.afterSave("BscTokenTransfers", async function (request) {
  const confirmed = request.object.get("confirmed");
  if (confirmed) {
    		const logger = Moralis.Cloud.getLogger();;"Token "+request.object.get("token_address"));"From "+request.object.get("from_address"));"Block "+request.object.get("block_number")); 
    		if(request.object.get("from_address") != "0x0000000000000000000000000000000000000000")
              	const options = {
                    address: request.object.get("token_address"),
                    chain: "bsc",
                    to_block: request.object.get("block_number"),
                const price = await Moralis.Web3API.token.getTokenPrice(options);
     "price "+price.usdPrice); 
				const BscTransfers = Moralis.Object.extend("BscTokenTransfers");
                const query = new Moralis.Query(BscTransfers);

                query.equalTo("transaction_hash", request.object.get("transaction_hash"));

                const result = await query.first({useMasterKey:true})
  } else {

The logger infos are working, i get all the datas i need from that request.
But the update of the column does not work (no error also, wich i dont understand)

and thats the log i get from the JSON.stringify(result)


as you can see, the “usdval” column is not listed … idk if it lists it because its “(undefined)” at the moment

but either way, the function runs through, and the value is still undefined

Try await, {useMasterKey:true})

1 Like

that worked perfectly! thank you very much!.
btw is there an easy way to clean the database ? just want to reload everything :slight_smile:

I don’t know of an easy way to do that. You can delete the data from a table directly in the dashboard.

ok thx. one last question… as i see the transaction_hash is not uniqe. Is there any way to get access to the objectId from the request? or is there anything unique i can use to query the right row?

and i want to rent a production server, is there any quick way to contact the support for a payment link?

For a production server you have to send an email to [email protected]

Not sure what you mean by from the request

Try .id if you have the result from a query

Moralis.Cloud.afterSave("BscTokenTransfers", async function (request) {

that part the “request” id does not contain the objectId of the database of course… but i need like something unique to query the database … as the transaction_hash is not unique (for example if a dividend-tracker is triggered…) … if not i just update all the same txhashes ^^

thx for the email, i will send them email now :slight_smile:

You have the id there in that request parameter. You can update directly the object from that request.

You can see what is in that request with

yeah i know that, but the objectID is always undefined, even if i can see it in the logger

it should be


but its undefined

did you try object.get("id") ?

yeah then i get SyntaxError: Unexpected identifier

what did you see in the request object with

also, make sure that you have latest version of moralis server

this should work

      "accept":"application/json, text/plain, */*",

this is btw the right objectId: SaoF3h20XVfgnbWaSoVH02OH

as you can see, its there… but i get undefined everytime ^^

the server is version 0.0.369

read the above reply, I edited it