Retrieve just deleted document

avalez picture avalez · Jun 1, 2012 · Viewed 18.4k times · Source

I deleted a document but I can still see it in _changes, so I can see last valid _rev, which is deleted, so get doc with id and last revision just returns:

{
  "_id":"25efa4ec8489d8b89b34c5cad6000059",
  "_rev":"3-a982bd6dccce8f405433f8453ab86880",
  "_deleted":true
}

and no other attributes.

How can I recover in this situation? Previous revision can not be seen in _changes. Will writing empty document (setting _deleted to false) help to see all revisions info?

Answer

avalez picture avalez · Jun 1, 2012

Ok, figured it out, if anyone interested:

  1. get deleted history, e.g.:

    curl http://example.iriscouch.com/test/_changes
    
  2. you'll see deleted documents with $id and $rev, put empty document as new version, e.g.:

    curl -X PUT http://example.iriscouch.com/test/$id?rev=$rev -H "Content-Type: application/json" -d {}
    
  3. now you can get all revisions info, e.g:

    curl http://example.iriscouch.com/test/$id?revs_info=true
    
  4. obtain version before deletion, e.g.:

    curl http://example.iriscouch.com/test/$id?rev=$prev_rev
    
  5. put it back to couchdb, e.g.:

    curl -X PUT http://example.iriscouch.com/test/$id?rev=$rev -H \'Content-Type: application/json\' -d \'$data\'
    

Let me know if you have any better way, or script.