[SOLVED] Issue querying Session table

How can I query the Session table from my backend? I am able to query User table with master key but Session table always returns empty results even when user sessions exist.

I have checked the table permissions and they are the same as the User table with reads being allowed.

Here is my code that works for retrieving all users:

  const query = new Moralis.Query("User");
  return query.find({ useMasterKey: true }).then((results: Array<Object>) => {
    functions.logger.info("No. of results: " + results.length);

This works, but when I switch the first line to new Moralis.Query("Session") I always get 0 results even when sessions exist.

I have tried this on MainNet and TestNet.

1 Like

It looks like this works fine for me:

Moralis.Cloud.define('get_sessions', async (request) => {
  const query = new Moralis.Query("_Session");
  x = await query.find({useMasterKey:true});
  return x;

That worked, thanks!

1 Like