Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
553 views
in Technique[技术] by (71.8m points)

couchdb - Retrieve just deleted document

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...