
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
- Issue with Education Plan Activation
I recently registered for the Appwrite Education Program through your official link: https://appwrite.io/education. While the registration process seemed to com...
- Migrating from one self-hosted instance ...
I am trying to migrate from an older VM running Appwrite 1.6 to a new VM with the latest version. On my new VM running Appwrite 1.7.4 I am going to migrations...
- Requests for listing documents are rando...
Using an iOS app generated with Capacitor, the requests for listing documents are slow in some ocassions. SOmetimes they are very fast, sometimes they are very ...
