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
- Use different email hosts for different ...
Hello, I have 2 projects and i want to be able to set up email templates in the projects. Both projects will have different email host configurations. I see ...
- Get team fail in appwrite function
I try to get team of a user inside appwrite function, but i get this error: `AppwriteException: User (role: guests) missing scope (teams.read)` If i try on cl...
- Deploy function not working - 503
Hellon i get this error message, when i try to deploy a new version of a function <html><body><h1>503 Service Unavailable</h1>No server is available to handle...