Skip to content

Instantly share code, notes, and snippets.

@laiso
Created December 14, 2018 06:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laiso/6ef8d2da13e09a48d1914500286e1033 to your computer and use it in GitHub Desktop.
Save laiso/6ef8d2da13e09a48d1914500286e1033 to your computer and use it in GitHub Desktop.
chunk loading
const query = firestore
.collection(`posts`)
.limit(200)
forEachDocs(query, docs => {
docs.map(doc => {
console.log(`${doc.id} do something`)
})
})
async function forEachDocs(query, handler) {
let snap = await query.get()
while (snap.size > 0) {
handler(snap.docs)
snap = await query
.startAfter(snap.docs.pop())
.get()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment