Firestore DeadlineExceeded exception for big collections

前端 未结 2 966
一个人的身影
一个人的身影 2021-01-02 20:06

I\'m trying to read bigger collections from Google Firestore for testing and archiving purposes. I\'m hitting some interesting errors when I try to get all documents from co

2条回答
  •  情歌与酒
    2021-01-02 20:43

    In my case I got this error just getting the entire collection. It was not even that big of a collection but I guess the documents in the collection are large. I did a paginated update. This was a node firebase function:

    let lastReadDoc = false;
    
    
    let lastDoc: string = '';
      const limitRecordCount = 10;
      do {
        await db
          .collection('something/' + somethingId + '/somethingcollection')
          .orderBy('id')
          .limit(limitRecordCount)
          .startAfter(lastDoc)
          .get()
          .then((snapshot: any) => {
            let counter = 0;
            snapshot.docs.forEach((doc: any) => {
              const docData = doc.data();
              if (lastDoc !== docData.id) {
                lastDoc = docData.id;
                counter = counter + 1;
              }
              // ***********************
              // business logic per doc here
              // ***********************
            });
            if (counter < limitRecordCount) {
              lastReadDoc = true;
            }
          })
          .catch((err: any) => {
            lastReadDoc = true;
            console.log('Error getting booking documents', err);
          });
      } while (lastReadDoc === false);
    

提交回复
热议问题