Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I query pouchdb for deleted documents?

I would like to list currently deleted documents in order to provide the ability to undelete one or more.

How can I query couchdb for deleted documents? I am actually using pouchdb.

Although this POST nicely describes how to query for and undelete a document, it requires an id of an existing doc.

I am looking for a way to query for all documents that have been deleted. The POST cites making a query for all changes. That query returns all documents that have been deleted IN ADDITION to any that have been edited/changed.

I am looking only for documents that have been deleted. Think querying for documents in the 'trash bin'. :)

like image 493
Larry Eitel Avatar asked Aug 11 '17 17:08

Larry Eitel


2 Answers

Starting from couch 2.1.0, you can add various selectors to _changes feed. So your request to output only deleted documents will be:

curl -X POST -H "content-Type: application/json" "http://adm:[email protected]:15984/tracks/_changes?filter=_selector" -d '{"selector": {"_deleted": true}}'

like image 66
Mayya Sharipova Avatar answered Sep 19 '22 19:09

Mayya Sharipova


You can add a filter to the _changes feed in PouchDB: https://pouchdb.com/api.html#filtered-changes

var changes = db.changes({
  filter: function(doc) {
    return doc._deleted;
  }
}).on('change', function(change) {
  console.log(change.id);
})
like image 27
Bernhard Gschwantner Avatar answered Sep 17 '22 19:09

Bernhard Gschwantner