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.
The pointer document
{
"_id" : "document1",
"versions" : [ "document1/308ef032a3801a" ]
}
The version document
{
"_id" : "document1/308ef032a3801a",
... actual content
}
Using faster disks, striped RAID arrays and modern file systems can all speed up your CouchDB deployment.
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.
Apache CouchDB (CouchDB (link resides outside IBM)) is an open source NoSQL document database that collects and stores data in JSON-based document formats.
CouchDB is a peer-based distributed database system.
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With