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'. :)
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}}'
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);
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With