You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by David Van Couvering <da...@vancouvering.com> on 2010/02/21 23:04:57 UTC
Selecting part of a multi-value key
I have a view that generates a type and a date as a composite key. This way
the results are sorted by type and then by date.
I would like to call the view so that I get all rows that match a given
type, regardless of date. I need them sorted by date.
Is this possible? I've tried varying syntaxes to no success. I'd prefer
not to generate separate views for each type, but I'll do that if that's the
only approach.
Thanks!
David
--
David W. Van Couvering
http://www.linkedin.com/in/davidvc
http://davidvancouvering.blogspot.com
http://twitter.com/dcouvering
Re: Selecting part of a multi-value key
Posted by David Van Couvering <da...@gmail.com>.
Great answers, all! Note that the view Wiki and the CouchDB book talk about
using an empty value or {} to select all rows that are a match for one
element in a compound key. IMHO key missing information.
Time permitting, I'll take a shot at the Wiki, unless someone else wants to
fix it.
David
On Mon, Feb 22, 2010 at 2:51 AM, Brian Candler <B....@pobox.com> wrote:
> On Sun, Feb 21, 2010 at 02:04:57PM -0800, David Van Couvering wrote:
> > I have a view that generates a type and a date as a composite key. This
> way
> > the results are sorted by type and then by date.
>
> That is, something like emit([doc.type,doc.date], ...) ?
>
> > I would like to call the view so that I get all rows that match a given
> > type, regardless of date. I need them sorted by date.
>
> startkey=["a_type"]&endkey=["a_type",{}]
>
> (with suitable URL encoding). They will still be sorted by date, because
> they are sorted by [type,date].
>
> For reduce values for all rows with a particular type, look at
> group_level=1
>
--
David W. Van Couvering
http://www.linkedin.com/in/davidvc
http://davidvancouvering.blogspot.com
http://twitter.com/dcouvering
Re: Selecting part of a multi-value key
Posted by Brian Candler <B....@pobox.com>.
On Sun, Feb 21, 2010 at 02:04:57PM -0800, David Van Couvering wrote:
> I have a view that generates a type and a date as a composite key. This way
> the results are sorted by type and then by date.
That is, something like emit([doc.type,doc.date], ...) ?
> I would like to call the view so that I get all rows that match a given
> type, regardless of date. I need them sorted by date.
startkey=["a_type"]&endkey=["a_type",{}]
(with suitable URL encoding). They will still be sorted by date, because
they are sorted by [type,date].
For reduce values for all rows with a particular type, look at group_level=1
Re: Selecting part of a multi-value key
Posted by Simon Metson <si...@googlemail.com>.
Hi,
something like ?group=true&startkey=['mytype', 0]&endkey=['mytype',
"A"] would work if your dates are numbers, if you have them as strings
something similar would work (lots of Z's...)
Cheers
Simon
On 21 Feb 2010, at 22:04, David Van Couvering wrote:
> I have a view that generates a type and a date as a composite key.
> This way
> the results are sorted by type and then by date.
>
> I would like to call the view so that I get all rows that match a
> given
> type, regardless of date. I need them sorted by date.
>
> Is this possible? I've tried varying syntaxes to no success. I'd
> prefer
> not to generate separate views for each type, but I'll do that if
> that's the
> only approach.
>
> Thanks!
>
> David
>
> --
> David W. Van Couvering
>
> http://www.linkedin.com/in/davidvc
> http://davidvancouvering.blogspot.com
> http://twitter.com/dcouvering
Re: Selecting part of a multi-value key
Posted by Nicholas Orr <ni...@zxgen.net>.
umm date = type...
so startkey=[type],endkey=[type,*]
2010/2/22 Nicholas Orr <ni...@zxgen.net>
> I think it is startkey=[date],endkey=[date, *]
>
> Nick
>
> 2010/2/22 David Van Couvering <da...@vancouvering.com>
>
>> I have a view that generates a type and a date as a composite key. This
>> way
>> the results are sorted by type and then by date.
>>
>> I would like to call the view so that I get all rows that match a given
>> type, regardless of date. I need them sorted by date.
>>
>> Is this possible? I've tried varying syntaxes to no success. I'd prefer
>> not to generate separate views for each type, but I'll do that if that's
>> the
>> only approach.
>>
>> Thanks!
>>
>> David
>>
>> --
>> David W. Van Couvering
>>
>> http://www.linkedin.com/in/davidvc
>> http://davidvancouvering.blogspot.com
>> http://twitter.com/dcouvering
>>
>
>
Re: Selecting part of a multi-value key
Posted by Nicholas Orr <ni...@zxgen.net>.
I think it is startkey=[date],endkey=[date, *]
Nick
2010/2/22 David Van Couvering <da...@vancouvering.com>
> I have a view that generates a type and a date as a composite key. This
> way
> the results are sorted by type and then by date.
>
> I would like to call the view so that I get all rows that match a given
> type, regardless of date. I need them sorted by date.
>
> Is this possible? I've tried varying syntaxes to no success. I'd prefer
> not to generate separate views for each type, but I'll do that if that's
> the
> only approach.
>
> Thanks!
>
> David
>
> --
> David W. Van Couvering
>
> http://www.linkedin.com/in/davidvc
> http://davidvancouvering.blogspot.com
> http://twitter.com/dcouvering
>
Re: Selecting part of a multi-value key
Posted by Patrick Barnes <mr...@gmail.com>.
Hi Barry,
There are three ways to select data out of a view...
A specific key: ?key=["foo"]
A number of specific keys: keys=[["foo"], ["bar"], ["baz"]] (Which is
passed in as user data on a POST request.
A contiguous region of keys, delimited by startkey and endkey.
If you have a view where each key looks like [$type, $date], then any
docs having a particular type will be adjacent to one another.
startkey=[$type] (with no second element) will be lexicographically
LOWER than any [$type, $date] key.
endkey=[$type, {}] (the second element is an empty object) will be
lexicographically HIGHER than any [$type, $date] key, as long as $date
is a string.
Does that work for you? The result set will still be ordered by $type
then $date (although with the above startkey and endkey every record
will have the same $type)
HTH,
-PB
On 22/02/2010 9:32 AM, Barry Wark wrote:
> Is there a reason you can't alos create a view indexed by date then type?
>
> Barry
>
>
>
> On Feb 21, 2010, at 2:04 PM, David Van Couvering
> <da...@vancouvering.com> wrote:
>
>> I have a view that generates a type and a date as a composite key.
>> This way
>> the results are sorted by type and then by date.
>>
>> I would like to call the view so that I get all rows that match a given
>> type, regardless of date. I need them sorted by date.
>>
>> Is this possible? I've tried varying syntaxes to no success. I'd prefer
>> not to generate separate views for each type, but I'll do that if
>> that's the
>> only approach.
>>
>> Thanks!
>>
>> David
>>
>> --
>> David W. Van Couvering
>>
>> http://www.linkedin.com/in/davidvc
>> http://davidvancouvering.blogspot.com
>> http://twitter.com/dcouvering
>
Re: Selecting part of a multi-value key
Posted by Barry Wark <ba...@gmail.com>.
Is there a reason you can't alos create a view indexed by date then
type?
Barry
On Feb 21, 2010, at 2:04 PM, David Van Couvering
<da...@vancouvering.com> wrote:
> I have a view that generates a type and a date as a composite key.
> This way
> the results are sorted by type and then by date.
>
> I would like to call the view so that I get all rows that match a
> given
> type, regardless of date. I need them sorted by date.
>
> Is this possible? I've tried varying syntaxes to no success. I'd
> prefer
> not to generate separate views for each type, but I'll do that if
> that's the
> only approach.
>
> Thanks!
>
> David
>
> --
> David W. Van Couvering
>
> http://www.linkedin.com/in/davidvc
> http://davidvancouvering.blogspot.com
> http://twitter.com/dcouvering