[SOLVED] How to retrieve all objects data in Moralis Database

Hi, I’m having trouble retrieving data from the moralis database.
I already sync my smartcontract event to moralis database
and i have 1 object inside “Membership” class in database
the problem is i want to retrieve and get all the information from Membership class but then it just return Screenshot_8

my question is how do i solved this problem using Moralis function so i can get all the data item from my Membership class

this is my code :

async function fetchMembership() {
    const Membership = Moralis.Object.extend("Membership");
    const query = new Moralis.Query(Membership);
    query.equalTo("creator", walletAddress);
    const result = await query.find();
  }

what doesn’t work? what it should return? you could use masterKey parameter if needed

when i look at network tabs it return all the data that i want
Screenshot_9

but i don’t know why when i run my code and console.log the result, its only show me
{_objCount: 1, className: "Membership", id: "xxxx"}

maybe you have to fetch the properties from that object in order to see them, with .get or with [] or other syntax, you can also try to use JSON.stringify

what you see with console.log may not be the entire object

whenever i try with .get its always return get is not a function

actually i just want to get 1 field value, which is the “contractURI” field, how do i do that using Moralis function?

i try to follow this tutorial, this is actually what i need, but its just doesnt work for me https://www.youtube.com/watch?v=l0NvTvNxpQo&t=384s

try various options, you can also use .select to get only a row

where do i find docs for using this function?

it is standard syntax from parse server, you will find that with a google search

the problem is, i try to filter the query using query.equalTo but then its just return me like this, the filter doesn’t working it return me all the data.
Screenshot_11
i tried all instruction from here https://v1docs.moralis.io/moralis-dapp/database/objects but none of these method is working

this is my code

  const { fetch } = useMoralisQuery(
    "Membership",
    query => query.equalTo("creator", walletAddress),
    [],
    { autoFetch: false }
  );

const objectIdQuery = () => {
    fetch({
      onSuccess: member=> {
        console.log(member);
        const name = member.get("creator");
        console.log(name);
        // The object was retrieved successfully.
      },
      onError: error => {
        // The object was not retrieved successfully.
        // error is a Moralis.Error with an error code and message.
      }
    });
  };

i just want to filter the items from my “Membership” class. if anyone can help me ill be very grateful

This seem to be react code. Can you explain again what is the issue now?

Yes im using react
as you can see i have 4 objects in my Membership class


and i want to filter out my objects, so lets say i only want to get data based on creator value or based on name value.
but its always return to me all the objects in Membership class

If you’re willing to get just one column, you can use the .select function having such

(query) => query.select("COLUMN_NAME"),

If you’re to filter based on a specific value, and maybe the value is coming from a state or somewhere as you got above, you can add the value as a dependency to the hook having such

query => query.equalTo("creator", walletAddress),
[walletAddress],

i have tried your solution but it stil didnt work
this is the result of query when i console log it
Screenshot_13

is it because the query result didn’t return “creator” and “name” column? so i cant filter it based on those value? i don’t know what happened

What browser is that? Looks like firefox :eyes:
If so, will suggest logging the attribute instead of checking from the console here or you should also try check from another browsers console, maybe chrome or brave

yes im using firefox,but the problem is my filter still not working, i even look at network tab and its return me all the objects in my membership class

im using :
“react-moralis”: “^1.3.5”
“moralis”: “^1.11.0”

Looking at the shot of your DB shared above,


The creator is all the same which you’re trying to filter with. You should check if your creator is the right field you want to filter with

1 Like

yes i realized that, but i also try to query it with
query => query.equalTo(“name”, “Raccoon Community”) but the filter still didn’t work. its weird, i have already read all the docs for save, query, update object. the only problem is when i want to query the data. do you have another solutions? or maybe you want to try it on your side?