
I have a list of documents that I want to query only for the respective "clients" collection that is in relationship with the "projects" collection.
Is that possible? Or should I query all the projects and then filter by clients?
const queryBuilder = () => {
const queryArray = []
if (search) {
queryArray.push(Query.search('name', search))
}
queryArray.push(Query.limit(limit))
queryArray.push(Query.offset(offset))
return queryArray
}
const getDocuments = async () => {
if (!database) return
await database.listDocuments(
Server.databaseId!,
Server.collections.projects!,
queryBuilder())
.then((res: any) => {
setprojects(res.documents)
setDocumentsCount(res.total)
})
.catch((err: Error) => {
showSnackbar(err.message, 'error')
})
}

Queries are not available for relationship at the moment
https://appwrite.io/docs/databases-relationships#query
So you will have to query all projects and filter by clients as you mention it

@Guille huh... but this works as expected thought... :
const queryArray = []
if (search) {
queryArray.push(Query.search('name', search))
}
if (clientId) {
queryArray.push(Query.equal('clients', clientId))
}
queryArray.push(Query.limit(limit))
queryArray.push(Query.offset(offset))
return queryArray
}

But seems like you are performing the query in the parent attributes not relational or I am wrong? 🤔

@Axentioi

I am querying the documents from the projects collection, and I want to only take the projects only for the related client so I added the Query.equal('clients'', clientId) which is the related client for the project so I get back the correct response

[Solved] How to query relationships in database.listDocuments()
Recommended threads
- AppwriteException: Project ID not found
I'm getting this error: `Error signing up: AppwriteException: Project with the requested ID could not be found. Please check the value of the X-Appwrite-Project...
- The Processing Loop
I was facing an issue while creating attributes for one of my collections so , is there any fix to this . It's been stuck in processing since 20 minutes. Here i...
- :rotating_light: CORS Error After Deploy...
Hi team, I'm facing an issue after deploying my React app to production. Issue: When trying to upload a file to Appwrite storage from the production domain `...
