cloudant / python-cloudant

A Python library for Cloudant and CouchDB
Apache License 2.0
163 stars 55 forks source link

How can I get revisions? | How to get data back by using id and revision code? #493

Closed yingshaoxo closed 3 years ago

yingshaoxo commented 3 years ago

How to get revisions

Here is the code:

db.create_document({
    #'_id': get_uuid(),
    '_id': "yingshaoxo",
    'sex': 'man',
    'age': 1 
})

doc = db["yingshaoxo"]

doc_url = doc.document_url
doc_rev = doc["_rev"]

response = db.r_session.get(doc_url + "?revs=true")
print(response.json())

For the above code, I could get the revisions:

{'_id': 'yingshaoxo',
 '_rev': '2-23264daadf4391d830db8b811aea35bb',
 'sex': 'girl',
 'age': 1,
 '_revisions': {'start': 2,
  'ids': ['23264daadf4391d830db8b811aea35bb',
   'cfb1374d66b1ffdcb7d0d9f0e33e01ce']}}

But when I use db["yingshaoxo"], I couldn't get _revisions, where is the problem, guys?

{'_id': 'yingshaoxo',
 '_rev': '2-23264daadf4391d830db8b811aea35bb',
 'sex': 'girl',
 'age': 1}

How to get data back by using _id and one element that comes from the _reversions?

This is essential if we want to recover some data from the history records.

rnewson commented 3 years ago

Hi,

Cloudant automatically deletes old revisions so you cannot rely on them being retrievable. If you need to preserve historical versions of your documents you will need a different tactic.

yingshaoxo commented 3 years ago

Hi,

Cloudant automatically deletes old revisions so you cannot rely on them being retrievable. If you need to preserve historical versions of your documents you will need a different tactic.

Alright, thank you for the answer.