Back

databases.listDocuments is returning null

  • 0
  • Web
Ilkhom
9 Oct, 2024, 23:20

export const getPatient = async (userId: string) => { try { const patients = await databases.listDocuments( DATABASE_ID!, PATIENT_COLLECTION_ID!, [Query.equal('userId', [userId])] )

TypeScript
return parseStringify(patients.documents[0])

} catch (error) { console.log(error) } }

im getting null here, not sure what am i doing wrong. I created relationship between patiens collection and appointment and its a one way

TL;DR
Issue: developers are experiencing 'databases.listDocuments' returning null when trying to retrieve patient data based on a given user ID. They are unsure why this is happening, even after creating a relationship between patient collection and appointment. Solution: The code snippet provided reveals the use of 'Query.equal' with array brackets around 'userId'. Developers should remove the square brackets to properly query the database. Update the code to look like this: ``` const patients = await databases.listDocuments( DATABASE_ID!, PATIENT_COLLECTION_ID!, [Query.equal('userId', userId)] ) ```
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