Error : DataService :: getExpenses :: error: AppwriteException: Server Error at Client.<anonymous> (http://localhost:5173/node_modules/.vite/deps/appwrite.js?v=60898c8d:850:17) at Generator.next (<anonymous>) at fulfilled (http://localhost:5173/node_modules/.vite/deps/appwrite.js?v=60898c8d:488:24)
please help i need to retirve specific user data by using their userId code :
async saveExpense({ expenseName, expense, expenseDate }) {
try {
const userId = localStorage.getItem('userId');
if (!userId) {
throw new Error("User not authenticated");
}
const data = {
userId,
expenseName,
expense,
expenseDate
};
return await this.databases.createDocument(
conf.appwriteDatabaseId,
conf.appwriteCollectionId,
ID.unique(),
data
);
} catch (error) {
console.log("DataService :: saveExpense :: error: ", error);
throw error;
}
}
async getExpenses() {
try {
const userId = localStorage.getItem('userId');
if (!userId) {
throw new Error("User not authenticated");
}
const response = await this.databases.listDocuments(
conf.appwriteDatabaseId,
conf.appwriteCollectionId,
['*'],
100,
0,
`userId=${userId}`
);
return response.documents;
} catch (error) {
console.log("DataService :: getExpenses :: error: ", error);
throw error;
}
}
}
const dataService = new DataService(); export default dataService;
Are you sure database ID is correct?
Also what's userID=${userId} for?
yes i am
userid is to retrieve data entered by specific user
Do you have an attribute with the user ID?
If so, it should be like this:
const response = await this.databases.listDocuments(
conf.appwriteDatabaseId,
conf.appwriteCollectionId,
[
Query.limit(100),
Query.equal("userID",[userId]),
],
);
Recommended threads
- Endless certificate generation cycle
Hello, when I try to add the subdomain stats.hedgehog-rp.ru, I get an infinite loop while the certificate is being generated. There are no problems with adding ...
- Realtime not working for some tables
Hi, I've got an issue where I can setup a realtime connection to listen to some tables, but some not all. I have two tables `history` and `users`. Both can be ...
- How to handle ghost accounts created by ...
Appwrite create the account with the email and send an invitation link with a secret. I am able to accept the invitation and add the account as a member on the ...