[SOLVED] How do we get a list of all users from moralis database?

How do we get a list of all users from moralis database?
And how to get values not from the current user?
I tried to make cloud functions according to the tutorial.

But they donโ€™t work for me. What am I doing wrong, please help me?

can you share your cloud code?


try with this code. It returns all the user list from your database.

// cloud code
Moralis.Cloud.define("getAllUser", async (request) => {
  const query = new Moralis.Query("User");
  const results = await query.find({ useMasterKey: true });
  return results;
});

// code to call the cloud function from your app
Moralis.Cloud.run("getAllUser").then((data) => {console.log(data)}) 

I get these errors: image

in my code:

did the function got uploaded successfully to cloud code?

How can I check it? maybe the problem lies in my very first screenshot? How do we get a list of all users from moralis database?

remove the import Moralis line. you dont have to add it here as it will available by default at server.

1 Like

yes, it works. thank you very much!