0

In a traditional relational database we can quickly checkup the number of rows or do a select count * from tableX query to know the answer. I am not finding an easy way to know this number in firestore. Let me know what's the easiest way to find the size of your tables(collections in firestore's case)

ishandutta2007
  • 16,676
  • 16
  • 93
  • 129
  • Firestore does not have count queries, or other aggregation operators. You will either have to load all documents or (much better) keep a running counter in the way shown here: https://firebase.google.com/docs/firestore/solutions/aggregation and here: https://firebase.google.com/docs/firestore/solutions/counters – Frank van Puffelen Jul 08 '20 at 02:31
  • Language please. I'm doing my best to help you here, and while it may be possible that I misinterpreted your question, the best way to ensure people can help you is by engaging in a civil dialog that clarifies the question and allows me to help better. As said: Firestore doesn't have aggregation functions built in, nor does it maintain any counters to access a document count. – Frank van Puffelen Jul 08 '20 at 02:35
  • Ok so you updated your comments , I didn't see, cool no issues, thanks for your two cents. :) – ishandutta2007 Jul 08 '20 at 02:38
  • 1
    Frank is right, Firestore doesn't offer any equivalent to a SQL "select count" query. The duplicate gives you several alternatives. – Doug Stevenson Jul 08 '20 at 02:39
  • @DougStevenson yes, but those are extremely costly operations to do at once, someone suggested to use a counter in firesore while adding docs the collection itself. Do you fee keeping a counter field in firestore for any potentially large collection is a wise design ? – ishandutta2007 Jul 08 '20 at 02:48
  • If it meets your needs, then do it. – Doug Stevenson Jul 08 '20 at 02:53
  • its not about meeting needs, it's about designing with a goal to minimise the cost of compute. Even all the answers in the other question has everything that meets needs but those may not be cheap if I have to do that once a day for all collections. I would give you a rough sense of the scale I need it for, I have about 100 collections, on each of the collections I need the count of number of documents once a day. And each of the collections can grow till 1M docs in a year or so. – ishandutta2007 Jul 08 '20 at 03:07

0 Answers0