Suppose you have a collection that contains hundreds of data.
I want to get a certain number of cases from there using limit () and repeat it in order. So-called paging.

const documentSnapshots = await fireStore.collection ('path'). limit (10) .get ();
console.log (snapshot.size);// I want it to be 10 until the last acquisition, but sometimes it will be and sometimes it will not.
const lastVisible = documentSnapshots.docs [documentSnapshots.docs.length --1];
const documentSnapshots2 = await fireStore.collection ('path'). limit (10) .startAfter (lastVisible) .get ();
// Continue until you can't get this

Since we are getting 10 items each, if there are 99 data items, size = 10 will continue 9 times in the image, and finally size = 9.

However, in reality, the number of acquisitions is more mixed, and just because the number of acquisitions is not 10 does not seem to be the last.

This behavior is not very intuitive, and when I make a UI for a paging list, the number of cases is sparse and it is a problem. Is this the usual behavior?

  • Answer # 1

    Is the source collection a frequently updated collection?
    When using Firestore I run paging on the client after getting the data.
    I'm sorry I couldn't help you.

Related articles