Back

Getting error while using Query.equal()

  • 0
  • Self Hosted
  • Web
  • Cloud
Flemoid (Saksham)
13 Mar, 2024, 21:54

The code snippet is:

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);
  }
}

If I remove Query, it is not showing error. With Query, it gives error.

Need Help!!

TL;DR
Issue: Error encountered while using Query.equal() in the getCurrentUser function. Solution: Update the code snippet as follows: ```javascript import { Query } from 'appwrite'; export async function getCurrentUser() { try { const currentAccount = await account.get(); if (!currentAccount) throw Error; const currentUser = await databases.listDocuments( appwriteConfig.databaseId, appwriteConfig.userCollectionId, [new Query().equal('accountId', currentAccount.$id)] ); if (!currentUser) throw Error; return currentUser.documents[0]; } catch (error) { console
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