[SOLVED] Moralis - how to query users? seems to not work

When querying for users (moralis/node version 1.3.2)
I get an empty array even with no filters, seems like it’s impossible to query for a user?
I want to find the Moralis user by its wallet address.

  // WORKS - returns array with transactions
  await Moralis.start({ serverUrl: SERVER_URL, appId: APP_ID });
  const transactions = await new Moralis.Query("EthTransactions")
      .find();

  // DOESN'T WORK - returns empty array
  await Moralis.start({ serverUrl: SERVER_URL, appId: APP_ID });
  const users = await new Moralis.Query("User")
    .find();

The User class has Read and Write enabled, and I do have users…

You need to use master key for that and to do it from a cloud function. That is because only current user can read his data by default.

1 Like

Thanks, just found out it’s a duplicate :zipper_mouth_face:
But it’s not very clear from the documentation, might make sense to update them to reflect this?

where in the documentation should be added that clarification?

Under Queries?

https://docs.moralis.io/moralis-server/database/queries

Maybe have an extra section named “Master key protected queries” or something like that? since it applies to a few queries, but when I see this, as part of all the other queries, I imagine it should work the same…

Then again, you have a notice that the MasterKey is required for example on a “distinct” query, but it says nothing about the User/Session queries.

now there is small info: https://docs.moralis.io/moralis-server/database/queries#using-master-key

1 Like