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) {
consoleRecommended threads
- Invalid query: Query on attribute has gr...
I cannot view the table within the Console
- Functions not executing after usage rese...
Hi team, Last month my project hit 100% usage and functions stopped working (expected). Now the new month has started and usage has reset, requests are going ...
- Functions never end and always fail (sta...
Hi ! I'm using Appwrite Cloud Pro and function execution from appwrite website is KO. Deploying starter function template, execution is always Failed and the ...