Problem with filter out records on EthNFTOwners

I would like to filter out all records from EthNFTOwners that does not match

token_address == “0xe804f5a2b14ae03345fffb89bded13a2ef5cefa7”

I made this cloud function

Moralis.Cloud.beforeSave("EthNFTOwners", (request) => {
  const logger = Moralis.Cloud.getLogger();
  logger.info("log EthNFTOwners"); 
  
  const token_address = request.object.get("token_address");
  logger.info(token_address); 
},{
  fields: {
    token_address : {
      required:true,
      options: token_address => {
        return token_address == "0xe804f5a2b14ae03345fffb89bded13a2ef5cefa7";
      },
      error: 'token address must be 0xe804f5a2b14ae03345fffb89bded13a2ef5cefa7'
    }
  }
});

The is that EthNFTOwners adds all records, not only ones with

token_address == “0xe804f5a2b14ae03345fffb89bded13a2ef5cefa7”

I see in the logs that function is running but it still save all tokens to EthNFTOwners, not only my contract ones

Please help how to solve this

Thank you

I think that I heard about not being able to remove an entry from a beforeSave hook.
You could try to use throw directly from an if, but it may have same behaviour.

You are interested in syncing data only for that specific contract address, and nothing more, nothing from your users?

You could also disable historical sync if you don’t needed it and add that contract address to sync address plugin.

As a work around, you could use a job to delete data that you don’t need.

Yes I want to sync only token ids from my contract. Don’t need others, and I only need EthNFTOwners.

I took this from Your example in docs

https://docs.moralis.io/moralis-server/cloud-code/triggers#beforesave

What if I could use AfterSave like this

Moralis.Cloud.afterSave("EthNFTOwners", async function(request) {
  const token_address = request.object.get("token_address");
  if (token_address != "0xe804f5a2b14ae03345fffb89bded13a2ef5cefa7"){
      await request.object.destroy();
  }
 
});

will this work ?

Aslo I know I could use http api

moralis.io/api/v2/nft/0xe804f5a2b14ae03345fffb89bded13a2ef5cefa7/owners

but if all 10 000 tokens are sold then this would return too big amount of data at once

that api should use pagination and will return only 500 items at a time

if you don’t need anything else besides that contract address synced, you could sync that address only, and not use authentication for your users, or sync that on a separate server

it may work that code with await request.object.destroy() too, as the object is already saved in the database, if needed you can also use master key there.

thank you this solves the problem

Moralis.Cloud.afterSave("EthNFTOwners", async function(request) {
  const token_address = request.object.get("token_address");
  if (token_address != "0xe804f5a2b14ae03345fffb89bded13a2ef5cefa7"){
      await request.object.destroy({ useMasterKey: true });
  }
});

Is it possible to disable EthTokenTransfers, EthTransactions but leave only EthNFTOwners ?

we don’t have this functionality to disable some tables now from what I know. You could delete data from those tables that you don’t want from time to time, so that it doesn’t slow the server if you don’t ned that data