[SOLVED] How to query equal to the ID

so i have a database with column _id

in my query I tried to do this but it returns none because the equalTo of ID I think is not right. because when I tried ethAddress instead with a specific value it returns something.

  const {data: claimData} = useMoralisQuery(
      "Transactions", 
      (query) =>
        query
          .equalTo("id", showTxnId), 
        [],
      );

If you try with ethAddress then it works?

Maybe you have to use a different name, did you also try with _id?

yes it works with ethAddress,

i tried _id it returns blank and there is an error in console of browser
Screen Shot 2022-12-23 at 11.32.12 PM

I hat was happening with id?

nothing. It just returns blank

when I tried ethAddress
the result is something like this.

Screen Shot 2022-12-23 at 11.50.39 PM

in mongo DB the _id itself is like the unique id that mongoDB created on its own. idk the correct syntax to have a equalTo query using moralis. I tried “id” and “_id” but both wont work

You can try on google for how to filter by id in parse server. Are you sure that you used the right ID value in that query?

yes I even tried hard coded

  const {data: claimData} = useMoralisQuery(
      "Transactions", 
      (query) =>
        query
          .equalTo("id", "IZmaApkHPu"), 
        [],
      );

This is in front end? Did you try objectId or another form of capitalization for it?

In the database is string and not an object, right?

still nothing.

yup it is a string not an object

Where from is that output? From a tool that connects directly to the database?

that is from mongoDb itself

If you make a normal query with Moralis.query then it works?

Try objectId instead of id.

1 Like

i tried objectId as well. not working :frowning:

IT WORKED! i tried objectId instead of ObjectId
edited

2 Likes