incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Szymon Kapeniak <szymon.kapen...@gmail.com>
Subject Re: How to get nested-key-sorted collection of documents
Date Mon, 23 Nov 2009 18:54:03 GMT
Thank you both, it helps a lot. I'll try this approach soon.
One question I have is in which version of couchdb group_level was introduced?
I currently work on 0.8...

2009/11/23 Brian Candler <B.Candler@pobox.com>:
> On Mon, Nov 23, 2009 at 08:58:04AM +1100, Mark Hammond wrote:
>> Here your map function looks something like:
>>
>> emit([doc.author, doc.date], null);
>>
>> Your rows will then be returned, with the _id, in order of author and
>> date.  You could query like:
>>
>> startkey=["Tolstoj", 1985], endkey=["Tolstoj", 1999]
>>
>> To query a range of dates for a single author.
> ...
>> Very similar:
>>
>> emit([doc.author, doc.date, doc.publisher], null);
>>
>> By using the group_level capability (see the wiki about the view API),
>> you could still search just by author, by author and date, or by all 3
>> fields.
>
> And of course you could use this view for the first query as well. A query
> for
>
>  startkey=["Tolstoj"]&endkey=["Tolstoj", {}]
>
> will still find all the relevant rows - it's just that this time they will
> be sorted by publisher and then _id, rather than just _id.
>
> If you have a reduce function (e.g. which counts books), then using
> group_level=2 would give you counts by author and year, independent of
> publisher.
>

Mime
View raw message