Google Cloud Firestore console reading of all documents and charges

前端 未结 3 536
太阳男子
太阳男子 2021-01-13 16:19

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 co

相关标签:
3条回答
  • 2021-01-13 16:42

    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.
    0 讨论(0)
  • 2021-01-13 16:48

    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.

    0 讨论(0)
  • 2021-01-13 16:51

    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 .

    0 讨论(0)
提交回复
热议问题