Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best Practice for CouchDB Document Versioning [closed]

Following my question here I am exmploring ideas for a generic approach to document versioning in CouchDB. While I imagine there may be no canonical approach, I had the following idea and am looking for feedback.

I would like to maintain readable document ids as much as possible, so a document existing at document1 would contain a pointer document to all existing versions on the system. The actual revision documents would be at something like document1/308ef032a3801a where 308ef032a3801a is some random number or hash.

Example

The pointer document

{
    "_id" : "document1",
    "versions" : [ "document1/308ef032a3801a" ]
}

The version document

{
    "_id" : "document1/308ef032a3801a",
    ... actual content
}
like image 869
Jacob Groundwater Avatar asked Nov 25 '11 22:11

Jacob Groundwater


People also ask

How can I speed up my CouchDB?

Using faster disks, striped RAID arrays and modern file systems can all speed up your CouchDB deployment.

What is a versioned document?

What Does Document Versioning Mean? Document versioning refers to the use and management of multiple versions of a document. This is more generally known as file versioning or file version management, for general file types.

How does CouchDB store data?

Apache CouchDB (CouchDB (link resides outside IBM)) is an open source NoSQL document database that collects and stores data in JSON-based document formats.

Is CouchDB distributed?

CouchDB is a peer-based distributed database system.


2 Answers

It's more typical to keep older versions of your document inside your current revision (either as JSON or, often, as an attachment). For the JSON case;

{
  "_id":"foo",
  "_rev":"3-fsfsfsdf",
  "foo":"current value of foo",
  "history": {
    "2": {
      "foo":"previous version of foo"
    },
    "1": {
      "foo":"initial version of foo"
    }
  }
}

Obviously this clutters things somewhat, which is why it's often simpler to push the full old version of the document into an attachment instead. This pattern is common enough that CouchDB ships with a library, jquery.couch.js, that implements it (in the saveDoc(doc) function).

like image 101
Robert Newson Avatar answered Oct 22 '22 03:10

Robert Newson


Here is some discussion about document versioning approaches:

http://jchrisa.net/drl/_design/sofa/_list/post/post-page?startkey=%5B%22Versioning-docs-in-CouchDB%22%5D

The one suggested approach is to stick older versions as attachments to the current doc. As the document mentions, it is simple, scalable, and replicates. The jquery couchdb library has this baked in which is nice.

like image 35
Ryan Ramage Avatar answered Oct 22 '22 03:10

Ryan Ramage