couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joe Freeman <joe.free...@bitroot.com>
Subject Re: Document versioning with multiple documents
Date Fri, 07 Jan 2011 08:58:16 GMT
I'm still confused about this. Does anyone have any suggestions?

Regarding the attachPrevRev approach: I noticed that Chris has posted
a comment on his blog[1] that mentions "a mode that loads attachments
into the view server". I presume this doesn't exist at the moment, but
are there any plans to implement something like this in the future?

Thanks.

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

On 2 January 2011 11:52, Joe Freeman <joe.freeman@bitroot.com> wrote:
> I'm trying to implement document versioning using a variation of the
> method described under 'Multiple Documents' here:
> http://blog.couchone.com/post/632718824/simple-document-versioning-with-couchdb
>
> (I'd like to have been able to use the 'attachPrevRev' approach, but
> unfortunately that doesn't seem to allow me to setup a view that lists
> all the revisions for a document - i.e., I can't access the older
> revisions (attachments) from the view server.)
>
> I have documents like this:
>
> {_id: '1', type: 'page'}
> {_id: '2', type: 'page_revision', page: '1', created_at: [2011, 1, 1,
> 11, 28, 0], content: 'First revision of first page.'}
> {_id: '3', type: 'page'}
> {_id: '4', type: 'page_revision', page: '3', created_at: [2011, 1, 1,
> 11, 29, 0], content: 'First revision of second page.'}
> {_id: '5', type: 'page_revision', page: '3', created_at: [2011, 1, 1,
> 11, 30, 0], content: 'Second revision of second page.'}
>
> My view then has a map function:
>
> function(doc) {
>  if (doc.type == 'page_revision') {
>    emit([doc.page, doc.created_at], doc);
>  }
> }
>
> Which emits the following keys:
>
> [1, [2011, 1, 1, 11, 28, 0]] // First revision of first page.
> [3, [2011, 1, 1, 11, 29, 0]] // First revision of second page.
> [3, [2011, 1, 1, 11, 30, 0]] // Second revision of second page.
>
> So I add a reduce function to get the latest revision for each page
> (and use group_level=1):
>
> function(keys, values) {
>  return values[values.length - 1];
> }
>
> When I try to run this, I get a 'reduce_overflow_error' ("Reduce
> output must shrink more rapidly"), and I think I understand why.
>
> However, if I change the reduce function to this:
>
> function(keys, values) {
>  return values[values.length - 1];
> /*aaaaaaaaaaaaaaaaaaaaaaa
> aaaaaaaaaaaaaaaaaaaaaaaaa
> aaaaaaaaaaaaaaaaaaaaaaaaa
> aaaaaaaaaaaaaaaaaaaaaaaaa
> aaaaaaaaaaaaaaaaaaaaaa*/
> }
>
> (i.e., pad out the content of the function with a comment)
>
> Then I don't get the overflow error, and I get the result I was expecting.
>
> So this raises two questions:
>
> 1) Does the fact that I initially get the overflow error suggest that
> there's something wrong with my approach?
>
> 2) Why don't I get the error in the second case?
>
> And hence, can anyone suggest how I should be solving this problem?
>
> Thanks :)
>

Mime
View raw message