K20 K20 - 1 year ago 141
Javascript Question

pouchdb delete allDocs javascript

I am new in pouchdb and I can't understand the API.

I want to know what is the best way to delete all documents with a javascript code. I try many things but nothing seams to work.

Do I have to use some options in the allDocs method like:

db.allDocs({include_docs: true, deleted: true})

Answer Source

Sorry the API is so confusing! If you can let us know how to improve it, that would be helpful. :)

You can either do db.destroy(), which completely erases the database but does not replicate the deletions, or you can individually remove() all documents:

db.allDocs().then(function (result) {
  // Promise isn't supported by all browsers; you may want to use bluebird
  return Promise.all(result.rows.map(function (row) {
    return db.remove(row.id, row.value.rev);
}).then(function () {
  // done!
}).catch(function (err) {
  // error!


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download