couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Blair Nilsson <blair.nils...@gmail.com>
Subject Re: startkey/endkey and descending=true
Date Wed, 17 Jun 2009 23:39:02 GMT
It is a range,[%22foo%22] is at the top, and [%22foo%22,{}] is right
down the bottom. since {} comes in the sort, I think after everything
else that can be there, certainly after strings and numbers.

For a query we use fairly often,

group=true&startkey=["Mark",4]&endkey=["Mark",4,{}]
gives us
{"rows":[
{"key":["Mark",4,"2009/06/10 00:00:00"],"value":[20,20,45]},
{"key":["Mark",4,"2009/06/11 00:00:00"],"value":[32,29,51]},
{"key":["Mark",4,"2009/06/12 00:00:00"],"value":[34,33,50]},
{"key":["Mark",4,"2009/06/13 00:00:00"],"value":[33,33,45]},
{"key":["Mark",4,"2009/06/14 00:00:00"],"value":[42,37,48]},
{"key":["Mark",4,"2009/06/15 00:00:00"],"value":[56,51,49]},
{"key":["Mark",4,"2009/06/16 00:00:00"],"value":[17,24,49]},
{"key":["Mark",4,"2009/06/17 00:00:00"],"value":[48,43,49]},
{"key":["Mark",4,"2009/06/18 00:00:00"],"value":[37,26,49]}
]}

to produce a reverse, we have to use
group=true&descending=true&startkey=["Mark",4,{}]&endkey=["Mark",4]

which will give us...

{"rows":[
{"key":["Mark",4,"2009/06/18 00:00:00"],"value":[37,26,49]},
{"key":["Mark",4,"2009/06/17 00:00:00"],"value":[48,43,49]},
{"key":["Mark",4,"2009/06/16 00:00:00"],"value":[17,24,49]},
{"key":["Mark",4,"2009/06/15 00:00:00"],"value":[56,51,49]},
{"key":["Mark",4,"2009/06/14 00:00:00"],"value":[42,37,48]},
{"key":["Mark",4,"2009/06/13 00:00:00"],"value":[33,33,45]},
{"key":["Mark",4,"2009/06/12 00:00:00"],"value":[34,33,50]},
{"key":["Mark",4,"2009/06/11 00:00:00"],"value":[32,29,51]},
{"key":["Mark",4,"2009/06/10 00:00:00"],"value":[20,20,45]}
]}

but if we use
group=true&descending=true&startkey=["Mark",4]&endkey=["Mark",4,{}]

we get
{"rows":[]}

and also
group=true&startkey=["Mark",4,{}]&endkey=["Mark",4]

also gives us
{"rows":[]}

Its a range, but since the range is everything that can be under a
key, it works for selecting everything selecting under a point in a
key array, its all good :)



On Thu, Jun 18, 2009 at 11:04 AM, Ross Bates<rbates@gmail.com> wrote:
> The syntax I'm using is something I picked up on the mailing list. It's
> supposed to allow you to select according the first value in the key array.
> I'm not using ranges or anything for the key. So if all docs look like this
>
> [foo, 123]
> [foo, 456]
> [bar, 123]
>
> ?startkey=[%22foo%22]&endkey=[%22foo%22,{}]<http://couch:5984/msg_db/_view/views/msg_by_tag_date?startkey=%5B%22Tag%22%5D&endkey=%5B%22Tag%22,%7B%7D%5D>
>
> would return this
>
> [foo, 123]
> [foo, 456]
>
>
>
>
>
>
> On Wed, Jun 17, 2009 at 5:58 PM, Blair Nilsson <blair.nilsson@gmail.com>wrote:
>
>> Maybe your start key and end key are around the wrong way for descending
>> order?
>>
>> On Thu, Jun 18, 2009 at 10:46 AM, Ross Bates<rbates@gmail.com> wrote:
>> > Hi All - I have a view that uses an array for it's key. I want to select
>> by
>> > the first value and sort by the second in descending order (it sorts
>> > properly in ascending order by default)
>> >
>> > I'm using this syntax to select the rows and everything works fine
>> >
>> >
>> http://couch:5984/msg_db/_view/views/msg_by_tag_date?startkey=[%22Tag%22]&endkey=[%22Tag%22,{}]<http://couch:5984/msg_db/_view/views/msg_by_tag_date?startkey=%5B%22Tag%22%5D&endkey=%5B%22Tag%22,%7B%7D%5D>
>> >
>> > but when I add the descending parameter like this:
>> >
>> >
>> http://couch:5984/msg_db/_view/views/msg_by_tag_date?descending=true&startkey=[%22Tag%22]&endkey=[%22Tag%22,{}]<http://couch:5984/msg_db/_view/views/msg_by_tag_date?descending=true&startkey=%5B%22Tag%22%5D&endkey=%5B%22Tag%22,%7B%7D%5D>
>> >
>> > couch.log indicates a 200 but I get 0 rows back.
>> >
>> > Is what am I trying to do possible?
>> >
>> > Thanks for any help!
>> >
>> > -Ross
>> >
>>
>

Mime
View raw message