Firestore Pagination (Node.js)

Jul 26, 2021
const pageSize = 10let blogQuery = db.collection('blog').orderBy('created')let snapshot = await blogQuery.limit(pageSize).get()let lastCreated = nullwhile (snapshot.size) {  console.log('batch', lastCreated)  for (const doc of snapshot.docs) {    console.log(doc.id)    lastCreated = doc.get('created')  }  /*  const last = snapshot.docs[snapshot.docs.length - 1];  lastCreated = last.get('created')   */  snapshot = await blogQuery.startAfter(lastCreated).limit(pageSize).get()}

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.