Back

Query.equal returns a general_query_invalid exception

  • 0
  • Databases
  • Auth
  • REST API
Dani
30 Mar, 2024, 17:52

Hi everyone!

I’ve been using for a project Appwrite, but I've been stuck by an error when using Query.equal in a function named getCurrentUser() . So the function is as follows:

TypeScript
export async function getCurrentUser() {
  try {
    const currentAccount = await account.get();

    if (!currentAccount) throw Error;

    const currentUser = await databases.listDocuments(
      appwriteConfig.databaseId,
      appwriteConfig.userCollectionId,
      [Query.equal('accountId', [currentAccount.$id])],
    );

    if (!currentUser) throw Error;

    return currentUser.documents[0];
  } catch (error) {
    console.log(error);
  }
}

The problem is when I test it a general_query_invalid error message appears with the following content:

TypeScript
{
    "message": "Invalid query: {\"method\":\"equal\",\"attribute\":\"accountId\",\"values\":[\"660844b00029df0d3719\"]}",
    "code": 400,
    "type": "general_query_invalid",
    "version": "0.12.130"
}

Find attached a picture of the USERS collection in the database, with the user trying to query to.

I reviewed the docs from appwrite and did not find anything different, so I don't understand why is it failing. I also reviewed the environment variables which are correctly used and tables in the database contain the needed fields to perform the query equal operation.

Has anybody experienced the same problem? Could you please help or point me in the right direction to solve the problem?

Version used:

TypeScript
    "appwrite": "^14.0.0",

Thanks in advance for your help and support!! 😄

TL;DR
Issue: Query.equal in getCurrentUser function is causing a general_query_invalid exception in Appwrite. Solution: The error is related to the Query.equal operation. Ensure the query setup is correct, in this case, the `account.$id` should not be wrapped in square brackets. Update the query like this: ``` Query.equal('accountId', currentAccount.$id) ```
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more