The revisions are tracked back through the beginning of time, but the content is not. The availability of previous revisions is a side-effect of the MVCC architecture, but the revision tracking is actually necessary for distributed updates and replication, .

This is still pretty easy to implement without relying on internals like this, though. Just use the POST interface to create your documents with UUID IDs, and have documents that look like (warning: untested):

  { type: "wikipage",
    name: "WikiTitle",
    version: 1 }

Then have a view called "LatestRev" with a map like:

  function(doc) {if(doc.type == 'wikipage') {emit(doc.name, doc}}

and a reduce like:

  function(_k, v) {
    var max = undefined;
    for(var i=0; i < v.length; i++) {
      if(!max || v[i].version > max.version) {
        max = v[i];
      }
    }
    return max;
  }

If you need to get specific past versions, then try a view with just a map like:

  function(doc) {
    if(doc.type == 'wikipage') {
      emit([doc.name,doc.version], doc);
    }
  }

Other questions like "what versions are available" are equally as simple.

Then you can do your regular couchdb compaction (and you won't break if a daemon is implemented to do that automatically (I can hope :) )), and still transparently get at previous versions.

Reply via email to