Rank 1: Thread
Something on the lines of
db = Databases(client)
db.count_documents(database_id, collection_id, queries=queries)
Votes
0
Replies
14
Participants
7
Messages
15
Rank 1: Thread
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
oooouh yeaaaaah, thats genius
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