[SOLVED] Retrieve value of objectId in a single table

I’m new to moralis, following the docs i have know that we can retrieve our data by using ‘objectId’ like this

const Monster = Moralis.Object.extend("Monster");
const query = new Moralis.Query(Monster);

//get monster with id xWMyZ4YEGZ
query.get("xWMyZ4YEGZ").then(
  (monster) => {
    // The object was retrieved successfully.
  },
  (error) => {
    // The object was not retrieved successfully.
    // error is a Moralis.Error with an error code and message.
  }
);```

But at this time i want to get the value of ‘objectId’ without copy and paste it, can i use this ?

query.get('objectId')

Base on the value of objectId, I can easily queries my data ! Looking for your response !
Thanks for your help!!!

You can use JSON.stringify(variable) to do some debugging to see how the data looks like.

I don’t know now at that object you are referring in particular from where you want to get the id.

In browser console in vanilla js you can also use console.log for debugging

1 Like

Thanks for your reply !
But in my case i wanna retrieve the data like this

Can you give me some advice ?
Thank you

you will get that id somehow, I don’t know the exact syntax, you can try with object.id

you can also try to do some logging/debugging

1 Like

Thanks for your help, I will try !

image

Like in this example in this case, I retrieve all the data in my NFT class

but when i try to console.log i get undefined
Can i have some advice ?

you need to use Moralis.Query to query the database. And the result from the query will be an array to you will need to use a loop to log the data.

example code to log the id’s:

const NFT = Moralis.Object.extend("NFT")
const nft = new Moralis.Query(NFT)
nft.find().then((data)=>{
    for(item of data){
    console.log(item.id)
}
})

Thanks for you help, may I ask you to explain what ‘item’ is ? and how to determine it ?
Thank you

item in the for-of loop runs loop through each element of data array.

1 Like

I got it ! Thanks for your help sir