10

I was working couchdb-python ( http://code.google.com/p/couchdb-python/ ) and i was wondering if I have any way to retrieve a full list of revisions that have occurred on a document level?

Suppose I have a database named "movies" and it contains several documents. Each of my documents have more than 3 revisions.

Can I retrieve my documents based on the revisions?

If yes, how? I didn't see any obvious method to do it using CouchDB-Python

BenMorel
  • 34,448
  • 50
  • 182
  • 322
DjangoRocks
  • 13,598
  • 7
  • 37
  • 52

2 Answers2

14

I am not sure about couchdb-python, however you can get the entire known revision history of a document via the HTTP API.

Learn all about it in the CouchDB Document API documentation.

A normal query:

$ curl jhs.couchone.com/db/doc
{ _id: 'doc',
  _rev: '3-825cb35de44c433bfb2df415563a19de' }

Add ?revs=true to see an array of old revisions.

$ curl jhs.couchone.com/db/doc?revs=true
{ _id: 'doc',
  _rev: '3-825cb35de44c433bfb2df415563a19de',
  _revisions: 
   { start: 3,
     ids: 
      [ '825cb35de44c433bfb2df415563a19de',
        '7051cbe5c8faecd085a3fa619e6e6337',
        '967a00dff5e02add41819138abb3284d' ] } }

Also you can add ?revs_info=true for more details about the revisions, such as whether they are still available (i.e. they were added after the last compaction and you can fetch them).

$ curl jhs.couchone.com/db/doc?revs_info=true
{ _id: 'doc',
  _rev: '3-825cb35de44c433bfb2df415563a19de',
  _revs_info: 
   [ { rev: '3-825cb35de44c433bfb2df415563a19de',
       status: 'available' },
     { rev: '2-7051cbe5c8faecd085a3fa619e6e6337',
       status: 'available' },
     { rev: '1-967a00dff5e02add41819138abb3284d',
       status: 'available' } ] }
JasonSmith
  • 72,674
  • 22
  • 123
  • 149
  • hello, thank you for your reply. Can i retrieve the document based on the revision history? For instance, document with ID: 132, revision 3? – DjangoRocks Feb 18 '11 at 06:46
  • Using the last method I showed `?revs_info=true`, you *can* see which revisions you can retrieve. They will show `status: 'available'`. However, CouchDB is always compacting, so you can not assume that your data will be there. – JasonSmith Feb 19 '11 at 08:19
2

The Database.revisions method may be what you want, http://code.google.com/p/couchdb-python/source/browse/couchdb/client.py#545.

Matt Goodall
  • 1,682
  • 10
  • 7