Skip to content

Instantly share code, notes, and snippets.

@danielAlbuquerque
Created January 20, 2019 23:21
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 danielAlbuquerque/39dfdefdfbdfcbed80912a5d64ea4eff to your computer and use it in GitHub Desktop.
Save danielAlbuquerque/39dfdefdfbdfcbed80912a5d64ea4eff to your computer and use it in GitHub Desktop.
Pouch pagination example
const pouchDB = require('pouchdb-node')
const db = new pouchDB('database_name')
let options = { limit: 5 }
async function fetchNextPage () {
try {
const result = await db.allDocs(options)
console.log(result.rows)
if (result.rows.length > 0) {
options.startKey = result.rows[result.rows.length - 1].id
options.skip = options.skip == undefined ? options.limit : options.skip + options.limit
}
} catch(e) {
console.error(e)
}
}
async function main() {
await fetchNextPage()
await fetchNextPage()
await fetchNextPage()
await fetchNextPage()
await fetchNextPage()
}
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment