7

I am new to Firestore so I have a Profiles and Users collections. In the Cloud Firestore Console when I click on Database > Firestore > Data tab > Profiles or > Users the console is reading ALL the documents in each collection. These reads are counted in the Usage tab. So my question is if I have lets say 500K documents in the Profiles collection and clicked on Data I will be charged for reading 500K docs just to view the first 25 docs only. Just clicking on Data tab the console reads all the docs of the first Collection.

I tried using the filter but to use it you will have to click on the Collection and read all the docs first then you can edit the filter.

Is this the way it works or is it my misunderstanding?

3 Answers 3

16

I faced the same confusion a while ago and upon digging down to the issue I learnt that all the data which gets loaded in the 'Data' tab of Firestore page does count towards the overall Firestore usage.

However, I was concerned with the same question as yours thus I contacted Firebase support. They reverted back confirming the first instinct of mine(Document reads in 'Data' tab does count) BUT initially it reads only the first 300 documents of ANY selected collection, so even if your collection has over 1 million docs, it will still load only the first 300 documents.

They suggested a way around it until the Firebase team finds a legit solution

  1. Bookmarking the Usage tab of the Firestore page. (So you basically 'Skip' the Data Tab and the useless 300 reads)
  2. Adding a dummy collection in a certain way that ensures it is the first collection(alphabetically) which gets loaded by default on the Firestore page.
2

So my question is if I have lets say 500K documents in the Profiles collection and clicked on Data I will be charged for reading 500K docs

Absolutely not! You are only charged with read operations for the documents that are apart of the query. I don't know the exact number at which the first query is limited but the data is loaded in smaller chunks, with other words a pagination system is implemented. So once you scroll down other elements are loaded and so on.

If you intend to create an app that uses Firestore as backend, please also note that, offline persistence:

For Android and iOS, offline persistence is enabled by default.

For the web, offline persistence is disabled by default. To enable persistence, call the enablePersistence method.

  • For the web, offline persistence is an experimental feature that is supported only by the Chrome, Safari, and Firefox web browsers. Also, if a user opens multiple browser tabs that point to the same Cloud Firestore database, and offline persistence is enabled, Cloud Firestore will work correctly only in the first tab.

This means, that once you get a document(s) from the Firebase servers, you are not charched anymore since the results are coming from the local cache.

5
  • Thanks Alex but every time I click on my Profiles or Users collections and after few minutes I go to Usage tab I notice that the number of reads increases by exactly the number of documents in each collection. Clicking on Data tab opens and reads all documents in the first collection in the collections pane. Clicking on one collection reads all documents and add them toward my Usage read count. Again I am talking the Console only not API form Andoird or iOS. There must be something that I am missing or this is the way it is.
    – AL-
    Feb 17, 2019 at 9:30
  • To make things more confusing to me is that it is counting not only the documents it is in fact counting the number of keys of each collection plus whatever objects on the right side panes. In my Profiles I have 42 documents and each time I click on Profiles the Usage counter increases by 84.
    – AL-
    Feb 17, 2019 at 10:03
  • Please see my updated answer. First time I was thinking at something else.
    – Alex Mamo
    Feb 17, 2019 at 11:19
  • The way the Console counts the reads is still not clear and confusing to me. I have added 100 documents to the Profiles collection making the total 142 docs. Now each time I click on Data the Usage Read counter increases by 300! Is there an explanation to this? I think the Console should not read and show any docs unless I, the user, tells it to do so by way of a query or filter before displaying and counting anything.
    – AL-
    Feb 19, 2019 at 6:22
  • Without seeing your code and the actual data, I cannot be much of a help. I've tested the number of reads in the same way you did and it worked correctly. Maybe you are doing some other read operations separately that you are not aware of.
    – Alex Mamo
    Feb 19, 2019 at 7:52
0

I just have a similar Question like and I find it redundant to post it as a Question so I'm posting it as asnswer,sorry for that,

Question:

this.db.collection(this.collectionName.usersCollection)
        .doc(currentUserId).collection(this.collectionName.friendsCollection)
        .where("friendID","==",id)    
        .get().then(snapshot =>{
          if(snapshot.empty)
          {

            this.db.collection(this.collectionName.chatsCollection).add({
              user1 : currentUserId,
              user2 : id
            }).then(docRef =>{
              docId = docRef.id;
              this.db.collection(this.collectionName.usersCollection)
              .doc(currentUserId)
              .collection(this.collectionName.friendsCollection).doc(docId)
              .set({

                friendID: id,

              })
              this.db.collection(this.collectionName.usersCollection).doc(id)
              .collection(this.collectionName.friendsCollection).doc(docId)
              .set({
                friendID:currentUserId,

               })
               resolve(docRef.id);
            })

          }
          else{
              snapshot.forEach(document =>{
                // console.log("friend id",document.data().friendID, "  docid: ",document.data().docId);
                resolve(document.id);
              })
          }
        })

so here I'm writing and reading the docId ,so will it affect the counts? I cannot have a check properly because with this many other operations are happening. Thanks .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.