Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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