Home > Blockchain >  How to retrieve data one by one from an array in the Firestore
How to retrieve data one by one from an array in the Firestore

Time:05-22

There is an array of about 30,000 words in the document.

enter image description here

I have been developing a mobile application. I want to retrieve the words here 6 by 6 depending on a certain condition. But if use "get()" function (as I show the below), When each user passes the next level, the application will read 30 thousand. To prevent this, I want to pull a certain number of data. Is there a method that allows me to pull the data one by one?

void readData() async {
    var _wordsDoc = await _firestore.collection('words').doc('tr').get();
    int index = userInfo.getLevel();
    int fireCounter = 1;
    for (int i = (index - 1) * 6; fireCounter <= 6; i  ) {
      Words.words.add(_wordsDoc['kelimeler'][i]);
      fireCounter  ;
    }
    setState(() {});
  }
}

CodePudding user response:

No, there is not. When you read a document, you always get the entire contents of the document. There is no way to limit that.

Your only workaround is to put each array item in a separate document, and query for only those documents you need.

  • Related