incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David King <>
Subject Re: Selectively keeping revisions around
Date Thu, 24 Jul 2008 05:52:26 GMT
> 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:  

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

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

   function(doc) {if(doc.type == 'wikipage') {emit(, 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.version], doc);

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

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.

View raw message