Is there a way to get the count of a collection instead of retrieving all of the data?
- 0
- 7
- Databases
Something on the lines of
db = Databases(client)
db.count_documents(database_id, collection_id, queries=queries)
just query all documents then limit to 1 document. in the response you will get a response.total thats the total number of documents in that collection
But this works on only documents less than 5000
is it possible to do it unlimited?
what if i have more then 5000 documents and want to get the total count?
They put 5000 for faster querying. Maybe lets wait for experts, they might give a way to add the limit
yah but right now i need this very urgent. One workarround would be to store the count of each collection seperately in another metadata collection, and increment or decreent it by a function, but how do i make sure that this count is actually in sync with the actual number of the ducuments.
Hi, I have the same problem. I was thinking if it's not possible to do it better using GraphQL's aggregation funciton: https://docs.8base.com/backend/graphql-api/grouping-and-aggregations/
I tried this approach, and it's working well with me: ```ts const response = await tablesDB.listRows({ databaseId: APPWRITE_DATABASE_ID, tableId: collectionId, queries: [Query.limit(1), Query.orderDesc("$sequence")], });
return response.rows[0].$sequence; ```
It works well with more than 5000 rows and less bandwidth usage
but what about count specific documents. by adding query. what happens to the sequence
sequence works like auto-incremental column, only the Issue with it when delete docs
in this case you use cursor to handle it
the way appwrite team recommends to do it, is kinda to have a function tied to the create and delete rows events, and update a table with counts for all the others tables
Recommended threads
- I'm getting an error on the console "j?....
On my self hosted instance version 1.8.1 the console is giving me this error when trying to view the rows for a table I recently created. My application is read...
- Websites hosted on my appwrite sites hav...
Hello, all my websites hosted on appwrite sites are not running I am getting this message "This site can’t be reached drivehub.appwrite.network took too long t...
- Database Write Limits hit
Hello Appwrite Admins, I'm a GitHub Education user, and about a week ago, my database was really badly optimized, resulting in about 600k writes in a single day...