User query returns empty array

I have a User in my db but when i run a query in my cloud function to get all users, i just see an empty array.

This user was created automatically when i ran Moralis.Web3.authenticate() on the front end.

my code cloud function code

const userQuery = new Moralis.Query("User");
const result = await userQuery.find();
logger.info(JSON.stringify(result));

Here is the user that was automatically added

However, if i manually create a user via the Moralis dashboard, this same query will return the newly created User but not the one that was automatically added.

What am i doing wrong?

You can’t query the user class without the master key as it’s protected sensitive data.

https://docs.moralis.io/moralis-server/cloud-code/cloud-functions-1#using-the-master-key-in-cloud-code

Don’t use master key on the frontend - only in cloud function.

2 Likes