IlkhomOriginal post
Web Developer
export const getPatient = async (userId: string) => {
try {
const patients = await databases.listDocuments(
DATABASE_ID!,
PATIENT_COLLECTION_ID!,
[Query.equal('userId', [userId])]
)
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
Summary
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)]
)
```