Google Cloud Firestore console reading of all documents and charges

无人久伴 提交于 2020-01-13 20:46:11

问题


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?


回答1:


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.




回答3:


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 .



来源:https://stackoverflow.com/questions/54729505/google-cloud-firestore-console-reading-of-all-documents-and-charges

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!