1

How Cloud Firestore billing works for getting the size of a collection, getting id of documents and for query snapshots?

Let's say if I am trying to make a query like below example will it make any charge?

const read=await this.afs.collection(‘users’).ref.get();
Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
Dev
  • 1,308
  • 3
  • 13
  • 24
  • What do you mean through "getting the size of a collection"? Do you want to count the number of documents within a collection? – Alex Mamo Mar 05 '19 at 09:55
  • yes of course,i want increase the counter according to size of collection – Dev Mar 05 '19 at 11:54
  • You can check **[this](https://stackoverflow.com/questions/48534676/how-to-count-the-number-of-documents-under-a-collection-in-firestore/48540276#48540276)** out. – Alex Mamo Mar 05 '19 at 11:56
  • OK,we can make counter to get the size of a collection.But my question is when i try to make a reference to a collection to get the size of that collection,how it effect to the firestore billing? – Dev Mar 05 '19 at 12:01

1 Answers1

2

According to your last comment:

But my question is when i try to make a reference to a collection to get the size of that collection,how it effect to the firestore billing?

If you only create a reference to a collection, you won't be charged but if you create a query that returns 5 elements, you'll be charged with 5 read operations.

According to the official documentation regarding Cloud Firestore billing:

There is a minimum charge of one document read for each query that you perform, even if the query returns no results.

So you're also charged with one document read, even if your query does not return any results.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • so when getting the size of a collection i am billing for getting one document from firestore,if i am correct.? – Dev Mar 05 '19 at 13:22
  • No, you're billed according to what operations you do. Please read that [answer](https://stackoverflow.com/questions/48534676/how-to-count-the-number-of-documents-under-a-collection-in-firestore/48540276#48540276) again. – Alex Mamo Mar 05 '19 at 13:32
  • till now your replies doesn’t answer my question.You said that billing is done according to our operation.My operation is only getting the size of a collection like this.const read=await this.afs.collection(‘users’).ref.get(); const sizeofCollection=read.size;see here i am not getting any documents insted i am only getting the size of a collection by making reference to that collection. – Dev Mar 07 '19 at 06:48
  • 1
    The number of read operations that you'll be charged when getting the size of a collection is equal to the number of document that exist wihin that collection. So let's say you want to get the size of a collection that has 5 document, it means that you'll be charged with 5 document reads. Is it clear now? – Alex Mamo Mar 07 '19 at 10:09
  • I still recommend you to store the number of documents within a collection in Firebase realtime database as explained in that answer. – Alex Mamo Mar 07 '19 at 10:10