Last active
August 9, 2016 17:41
-
-
Save davisp/8484f2a8187dd214cae0fcde4d0c2440 to your computer and use it in GitHub Desktop.
How to restore a deleted document on Cloudant
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ acurl 'https://davisp.cloudant.com/test-db/_all_docs?keys=["foo"]' | python -m json.tool | |
| { | |
| "rows": [ | |
| { | |
| "id": "foo", | |
| "key": "foo", | |
| "value": { | |
| "deleted": true, | |
| "rev": "2-eec205a9d413992850a6e32678485900" | |
| } | |
| } | |
| ], | |
| "total_rows": 7 | |
| } | |
| $ acurl 'https://davisp.cloudant.com/test-db/foo?rev=2-eec205a9d413992850a6e32678485900&revs=true' | python -m json.tool | |
| { | |
| "_deleted": true, | |
| "_id": "foo", | |
| "_rev": "2-eec205a9d413992850a6e32678485900", | |
| "_revisions": { | |
| "ids": [ | |
| "eec205a9d413992850a6e32678485900", | |
| "967a00dff5e02add41819138abb3284d" | |
| ], | |
| "start": 2 | |
| } | |
| } | |
| $ acurl https://davisp.cloudant.com/test-db/foo?rev=1-967a00dff5e02add41819138abb3284d | python -m json.tool | |
| { | |
| "error": "not_found", | |
| "reason": "missing" | |
| } | |
| $ # A curious corner case | |
| $ cat foo.json | |
| { | |
| "_id": "foo", | |
| "_rev": "2-eec205a9d413992850a6e32678485900", | |
| "stuff": "bar" | |
| } | |
| $ acurl -X PUT https://davisp.cloudant.com/test-db/foo -d @foo.json | python -m json.tool | |
| { | |
| "error": "conflict", | |
| "reason": "Document update conflict." | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In this particular case the previous revision is
not_foundwhich means this db has been compacted since the deletion. In this instance I would have been out of luck reviving the document. However, if that had returned a valid document it would have been as simple as copying the body, removing the _rev value and storing it back into the database.