Can anyone help me? I have used Appwrite multiple times before, but this time, I created a new project, and it is not interacting with the database. It's a fresh project, and I even tried recreating the project, but it still didn’t work. You can see the response I’m getting from the image below.
Are you sure your project id is defined?
yes
can you verify that for me? Console log it?
see
so, the get document by id function is saying the document cannot be found? Is that the only issue?
Documents are not being created. I tried adding data manually for the user ID, but it still shows an error when trying to fetch. manualdata entry is only working
Could you show the error from your post request for making a document?
actually this time post req working , only get req show error
idk how previously giving error
I would think that would be the case in your sync function?
If the user document does exist it will throw and error and create that document?
see this data is passing
export const syncUserWithAppwrite = async (user) => { const { id, username, emailAddresses } = user; console.log("Syncing user with Appwrite:", id, username, emailAddresses[0].emailAddress); try { try { // Try to fetch the document by user id const existingUser = await databases.getDocument( conf.databaseID, conf.UsersCollectionID, id ); // If user exists, skip adding if (existingUser) { console.log('User already exists in Appwrite'); return; // or handle the case where user already exists } } catch (error) { // Handle the case where the document does not exist if (error.message.includes('Document not found')) { // Add user to Appwrite if not exists await databases.createDocument(conf.databaseID, conf.UsersCollectionID, { userId: id, username: username, email: emailAddresses[0].emailAddress, }); } else { console.error('Error checking existing user:', error); } } } catch (error) { console.error("Error syncing user:", error); } };
for this function
but i tried to add the data manually to database then also not fetching
are you sure the document you created manually has the id you're looking for?
yep see
you need to use the document id
which is not user_guid
Oh shit, how i made a silly mistake. Thank you, sir, for helping!
haha no problem, sometimes a second set of eyes is all you need
i thought i was passing same data for the Id and userId
lmk if that fixes it for you
as for that other image about the project id, I think that's just because you didn't pass the project id header in the get request.
I also thought the project ID wasn’t being passed, which is why it was giving an error. I didn’t check it carefully. There’s so much to learn thanks
[SOLVED] Not able to interact with database
Recommended threads
- not able to extract anything from create...
when using createEmailPasswordSession const session = await account.createEmailPasswordSession(email, password) i am able to get the session but when using co...
- ⨯ AppwriteException: Invalid redirect
my vercel logs ```⨯ AppwriteException: Invalid redirect at _Client.redirect (node_modules/node-appwrite/dist/client.mjs:255:13) at async Account.createO...
- Database collection attribute struck in ...
during collection create