Skip to content

Instantly share code, notes, and snippets.

@davisp
Last active August 9, 2016 17:41
Show Gist options
  • Select an option

  • Save davisp/8484f2a8187dd214cae0fcde4d0c2440 to your computer and use it in GitHub Desktop.

Select an option

Save davisp/8484f2a8187dd214cae0fcde4d0c2440 to your computer and use it in GitHub Desktop.
How to restore a deleted document on Cloudant
$ 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."
}
@davisp
Copy link
Copy Markdown
Author

davisp commented Aug 9, 2016

In this particular case the previous revision is not_found which 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment