incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Davis <paul.joseph.da...@gmail.com>
Subject Re: Reduce parameters?
Date Tue, 01 Feb 2011 18:04:18 GMT
On Tue, Feb 1, 2011 at 12:32 PM, Joe Freeman <joe.freeman@bitroot.com> wrote:
> On 1 February 2011 16:08, Paul Davis <paul.joseph.davis@gmail.com> wrote:
>> I'm not entirely certain what you're wanting for output. Could you
>> give an example of what you'd hoped to achieve?
>
> Sorry, let me try and give a better explanation...
>
> A document (in my application; not a CouchDB document) is made up of a
> number of parts. Each part is stored in a CouchDB document, and
> contains four properties: 'document_id', 'timestamp', 'content' and
> 'revisions'. The 'revisions' property is an array of previous
> revisions. So a document might look like this:
>
> {
>  "_id": "part1.1",
>  "document_id": "document1",
>  "timestamp": 1294696806874,
>  "content": "part 1.1, revision 3",
>  "revisions": [
>    {
>      "updated": 1294696793572,
>      "content": "part 1.1, revision2",
>    },{
>      "updated": 1294696769516,
>      "content": "part 1.1, revision1",
>    }
>  ]
> }
>
> I can query the view to get 'all the latest part revisions for a
> document', but I don't seem to be able to 'get all the latest part
> revisions for a document as it was at a specified point in history'.
>
> So, to go back to my original example, and re-introduce a couple more
> parts, I might have:
>
> ["document1",1294696806874] -> {"content": "part 1.1, revision 3"}
> ["document1",1294696793572] -> {"content": "part 1.1, revision 2"}
> ["document1",1294696769516] -> {"content": "part 1.1, revision 1"}
> ["document1",1294696816974] -> {"content": "part 1.2, revision 2"}
> ["document1",1294696761684] -> {"content": "part 1.2, revision 1"}
> ["document1",1294696709610] -> {"content": "part 1.3, revision 1"}
>
> From this, I might want to say, give me the latest revisions at
> 1294696800000 (10th Jan 2011, 22:00:00 GMT), and I'd like the view to
> return:
>
> ["document1",1294696793572] -> {"content": "part 1.1, revision 2"}
> ["document1",1294696761684] -> {"content": "part 1.2, revision 1"}
> ["document1",1294696709610] -> {"content": "part 1.3, revision 1"}
>
> Note that "part 1.1, revision 3" and "part 1.2, revision 2" are not
> included because they have timestamps later than the specified time,
> and "part 1.1, revision 1" is not included because it is has a
> timestamp earlier than the latest revision.
>
> The closest I have got is to specify startkey and endkey of
> '["document1",0]' and '["document1",1294696800000]', which gives me:
>
> ["document1",1294696793572] -> {"content": "part 1.1, revision 2"}
> ["document1",1294696769516] -> {"content": "part 1.1, revision 1"} *
> ["document1",1294696761684] -> {"content": "part 1.2, revision 1"}
> ["document1",1294696709610] -> {"content": "part 1.3, revision 1"}
>
> The problem being that "part 1.1, revision 1" is still there, but I
> don't want it to be, because a later revision is present ("content":
> "part 1.1, revision 2").
>
> Essentially what I think I need to do at this point is 'GROUP BY' the
> part's ID. But I don't think I can do this because the part ID isn't
> in the emitted key.
>
> Does that make sense..?
>

Oh, gotchya.

I don't see anything direct with a view for this either. You could do
it for a given part at a time, but not all parts in one request. One
thing you might try is to use a _list function with your original set
up to discard results you don't need.

Mime
View raw message