You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Fabio Batalha Cunha dos Santos <fa...@scielo.org> on 2011/02/23 18:54:42 UTC

startkey and endkey problems

Hello All,

I'm using startkey and endkey in many situations but the one in question I
can't figure out why isn't working.

For example the following view.

{"total_rows":19845,"offset":0,"rows":[
{"id":"00d8a5b0-9d31-4c4b-a6a8-6a6818be0f13","key":"2176-945120100005","value":null},
{"id":"ffcaac85-9dc7-441d-8cce-db54fb0d6d85","key":"2176-945120100004","value":null},
{"id":"bd9535a9-2713-46be-b046-69cb049dad9b","key":"2176-945120100003","value":null},
{"id":"6b91498e-5b31-4c10-8265-5c0b26edeb24","key":"2176-945120100002","value":null},
{"id":"969b959b-fd2f-4475-ad63-11345e1a9f70","key":"2176-945120100001","value":null},
{"id":"9406d63b-e268-45fa-a1ef-483963571be1","key":"2176-945120100001","value":null},
{"id":"573539df-f554-4cca-961b-b658e56f3457","key":"2176-945120100001","value":null},
{"id":"6c33f7d0-3211-4154-90f5-2b50fec0fbcf","key":"2071-076320100001","value":null},
{"id":"2b2f07e2-5c08-4cae-b3bd-2519a69a7e62","key":"2071-076320090001","value":null},
{"id":"62a7dd81-a710-4358-9449-fcbfcccc4049","key":"2011-758220100002","value":null},
{"id":"966ba99b-3edc-4da5-89f3-28e32edc1625","key":"2011-758220100001","value":null},
{"id":"f15c268a-41f7-4ef3-92d2-c1516101e121","key":"2011-758220090004","value":null},
{"id":"ac88d963-e26e-4add-8a75-5d0287feb97f","key":"2011-758220090003","value":null},
{"id":"84abbd88-8268-4b31-a90e-31a55a137e37","key":"2011-758220090002","value":null},
{"id":"afe0f6bb-a14f-47fa-885a-f7b9bf33f2a5","key":"2011-758220090001","value":null},
{"id":"7d7b6733-0c62-41ab-95aa-b01cd1f5d90e","key":"2011-758220080004","value":null},
{"id":"22afed26-2995-4ffc-92d5-b0bdb3c18849","key":"2011-758220080003","value":null},
{"id":"ca3a81f0-017c-4680-b25c-0babd6f5afd1","key":"2011-758220080002","value":null},
{"id":"c9fda101-fd75-4990-862f-25fc8b936d1f","key":"2011-758220080001","value":null},
{"id":"e384832d-8378-4ab4-98c5-cf7f9ed011cd","key":"2011-758220070004","value":null}
]}


When I try to recover the keys that starts with "2176-9451" I try the
following query:
http://homolog.webservices.scielo.org/scieloorg/_design/couchdb/_view/issue_id?startkey=["2176-9451",{}]&endkey["2176-9451"]

But this query results an empty json.

The result is empty even if I try a query just with the startkey:
http://homolog.webservices.scielo.org/scieloorg/_design/couchdb/_view/issue_id?startkey=["2176-9451"]

Anybody have any idea why it is not working?


Thanks in advance,

*Fabio Batalha C. Santos*
Colegiado SciELO
www.scielo.org
FAPESP - CNPq - BIREME - FapUNIFESP

Re: startkey and endkey problems

Posted by Aurélien Bénel <au...@utt.fr>.
Dear Fabio,

> ...

> {"id":"e384832d-8378-4ab4-98c5-cf7f9ed011cd","key":"2011-758220070004","value":null}
> ]}
> http://homolog.webservices.scielo.org/scieloorg/_design/couchdb/_view/issue_id?startkey=["2176-9451",{}]&endkey["2176-9451"]
> But this query results an empty json.

There are two problems:

1. "startkey" should be lesser than "endkey".

2. When you have simple keys, don't use brackets.


Regards,

Aurélien

Re: startkey and endkey problems

Posted by Fabio Batalha <fa...@gmail.com>.
Thanks for all!!!

It was my mistake I was messing a multiple array key with a single key.

Thanks,
Fabio

On Wed, Feb 23, 2011 at 3:08 PM, Robert Johnson <ro...@rowanshire.net>wrote:

> Fabio
>
> As you are trying to do a partial key search I think you need
>
> startkey="2176-9451"
> endkey="2176-9451\u9999"
>
> ("\u9999" is the biggest unicode character you can get)
>
> Bob
>
>
>
> On 23 Feb 2011, at 17:54, Fabio Batalha Cunha dos Santos wrote:
>
> > Hello All,
> >
> > I'm using startkey and endkey in many situations but the one in question
> I
> > can't figure out why isn't working.
> >
> > For example the following view.
> >
> > {"total_rows":19845,"offset":0,"rows":[
> >
> {"id":"00d8a5b0-9d31-4c4b-a6a8-6a6818be0f13","key":"2176-945120100005","value":null},
> >
> {"id":"ffcaac85-9dc7-441d-8cce-db54fb0d6d85","key":"2176-945120100004","value":null},
> >
> {"id":"bd9535a9-2713-46be-b046-69cb049dad9b","key":"2176-945120100003","value":null},
> >
> {"id":"6b91498e-5b31-4c10-8265-5c0b26edeb24","key":"2176-945120100002","value":null},
> >
> {"id":"969b959b-fd2f-4475-ad63-11345e1a9f70","key":"2176-945120100001","value":null},
> >
> {"id":"9406d63b-e268-45fa-a1ef-483963571be1","key":"2176-945120100001","value":null},
> >
> {"id":"573539df-f554-4cca-961b-b658e56f3457","key":"2176-945120100001","value":null},
> >
> {"id":"6c33f7d0-3211-4154-90f5-2b50fec0fbcf","key":"2071-076320100001","value":null},
> >
> {"id":"2b2f07e2-5c08-4cae-b3bd-2519a69a7e62","key":"2071-076320090001","value":null},
> >
> {"id":"62a7dd81-a710-4358-9449-fcbfcccc4049","key":"2011-758220100002","value":null},
> >
> {"id":"966ba99b-3edc-4da5-89f3-28e32edc1625","key":"2011-758220100001","value":null},
> >
> {"id":"f15c268a-41f7-4ef3-92d2-c1516101e121","key":"2011-758220090004","value":null},
> >
> {"id":"ac88d963-e26e-4add-8a75-5d0287feb97f","key":"2011-758220090003","value":null},
> >
> {"id":"84abbd88-8268-4b31-a90e-31a55a137e37","key":"2011-758220090002","value":null},
> >
> {"id":"afe0f6bb-a14f-47fa-885a-f7b9bf33f2a5","key":"2011-758220090001","value":null},
> >
> {"id":"7d7b6733-0c62-41ab-95aa-b01cd1f5d90e","key":"2011-758220080004","value":null},
> >
> {"id":"22afed26-2995-4ffc-92d5-b0bdb3c18849","key":"2011-758220080003","value":null},
> >
> {"id":"ca3a81f0-017c-4680-b25c-0babd6f5afd1","key":"2011-758220080002","value":null},
> >
> {"id":"c9fda101-fd75-4990-862f-25fc8b936d1f","key":"2011-758220080001","value":null},
> >
> {"id":"e384832d-8378-4ab4-98c5-cf7f9ed011cd","key":"2011-758220070004","value":null}
> > ]}
> >
> >
> > When I try to recover the keys that starts with "2176-9451" I try the
> > following query:
> >
> http://homolog.webservices.scielo.org/scieloorg/_design/couchdb/_view/issue_id?startkey=[
> "2176-9451",{}]&endkey["2176-9451"]
> >
> > But this query results an empty json.
> >
> > The result is empty even if I try a query just with the startkey:
> >
> http://homolog.webservices.scielo.org/scieloorg/_design/couchdb/_view/issue_id?startkey=[
> "2176-9451"]
> >
> > Anybody have any idea why it is not working?
> >
> >
> > Thanks in advance,
> >
> > *Fabio Batalha C. Santos*
> > Colegiado SciELO
> > www.scielo.org
> > FAPESP - CNPq - BIREME - FapUNIFESP
>
>

Re: startkey and endkey problems

Posted by Robert Johnson <ro...@rowanshire.net>.
Fabio

As you are trying to do a partial key search I think you need

startkey="2176-9451"
endkey="2176-9451\u9999"

("\u9999" is the biggest unicode character you can get)

Bob



On 23 Feb 2011, at 17:54, Fabio Batalha Cunha dos Santos wrote:

> Hello All,
> 
> I'm using startkey and endkey in many situations but the one in question I
> can't figure out why isn't working.
> 
> For example the following view.
> 
> {"total_rows":19845,"offset":0,"rows":[
> {"id":"00d8a5b0-9d31-4c4b-a6a8-6a6818be0f13","key":"2176-945120100005","value":null},
> {"id":"ffcaac85-9dc7-441d-8cce-db54fb0d6d85","key":"2176-945120100004","value":null},
> {"id":"bd9535a9-2713-46be-b046-69cb049dad9b","key":"2176-945120100003","value":null},
> {"id":"6b91498e-5b31-4c10-8265-5c0b26edeb24","key":"2176-945120100002","value":null},
> {"id":"969b959b-fd2f-4475-ad63-11345e1a9f70","key":"2176-945120100001","value":null},
> {"id":"9406d63b-e268-45fa-a1ef-483963571be1","key":"2176-945120100001","value":null},
> {"id":"573539df-f554-4cca-961b-b658e56f3457","key":"2176-945120100001","value":null},
> {"id":"6c33f7d0-3211-4154-90f5-2b50fec0fbcf","key":"2071-076320100001","value":null},
> {"id":"2b2f07e2-5c08-4cae-b3bd-2519a69a7e62","key":"2071-076320090001","value":null},
> {"id":"62a7dd81-a710-4358-9449-fcbfcccc4049","key":"2011-758220100002","value":null},
> {"id":"966ba99b-3edc-4da5-89f3-28e32edc1625","key":"2011-758220100001","value":null},
> {"id":"f15c268a-41f7-4ef3-92d2-c1516101e121","key":"2011-758220090004","value":null},
> {"id":"ac88d963-e26e-4add-8a75-5d0287feb97f","key":"2011-758220090003","value":null},
> {"id":"84abbd88-8268-4b31-a90e-31a55a137e37","key":"2011-758220090002","value":null},
> {"id":"afe0f6bb-a14f-47fa-885a-f7b9bf33f2a5","key":"2011-758220090001","value":null},
> {"id":"7d7b6733-0c62-41ab-95aa-b01cd1f5d90e","key":"2011-758220080004","value":null},
> {"id":"22afed26-2995-4ffc-92d5-b0bdb3c18849","key":"2011-758220080003","value":null},
> {"id":"ca3a81f0-017c-4680-b25c-0babd6f5afd1","key":"2011-758220080002","value":null},
> {"id":"c9fda101-fd75-4990-862f-25fc8b936d1f","key":"2011-758220080001","value":null},
> {"id":"e384832d-8378-4ab4-98c5-cf7f9ed011cd","key":"2011-758220070004","value":null}
> ]}
> 
> 
> When I try to recover the keys that starts with "2176-9451" I try the
> following query:
> http://homolog.webservices.scielo.org/scieloorg/_design/couchdb/_view/issue_id?startkey=["2176-9451",{}]&endkey["2176-9451"]
> 
> But this query results an empty json.
> 
> The result is empty even if I try a query just with the startkey:
> http://homolog.webservices.scielo.org/scieloorg/_design/couchdb/_view/issue_id?startkey=["2176-9451"]
> 
> Anybody have any idea why it is not working?
> 
> 
> Thanks in advance,
> 
> *Fabio Batalha C. Santos*
> Colegiado SciELO
> www.scielo.org
> FAPESP - CNPq - BIREME - FapUNIFESP


Re: startkey and endkey problems

Posted by Paul Davis <pa...@gmail.com>.
On Wed, Feb 23, 2011 at 12:54 PM, Fabio Batalha Cunha dos Santos
<fa...@scielo.org> wrote:
> Hello All,
>
> I'm using startkey and endkey in many situations but the one in question I
> can't figure out why isn't working.
>
> For example the following view.
>
> {"total_rows":19845,"offset":0,"rows":[
> {"id":"00d8a5b0-9d31-4c4b-a6a8-6a6818be0f13","key":"2176-945120100005","value":null},
> {"id":"ffcaac85-9dc7-441d-8cce-db54fb0d6d85","key":"2176-945120100004","value":null},
> {"id":"bd9535a9-2713-46be-b046-69cb049dad9b","key":"2176-945120100003","value":null},
> {"id":"6b91498e-5b31-4c10-8265-5c0b26edeb24","key":"2176-945120100002","value":null},
> {"id":"969b959b-fd2f-4475-ad63-11345e1a9f70","key":"2176-945120100001","value":null},
> {"id":"9406d63b-e268-45fa-a1ef-483963571be1","key":"2176-945120100001","value":null},
> {"id":"573539df-f554-4cca-961b-b658e56f3457","key":"2176-945120100001","value":null},
> {"id":"6c33f7d0-3211-4154-90f5-2b50fec0fbcf","key":"2071-076320100001","value":null},
> {"id":"2b2f07e2-5c08-4cae-b3bd-2519a69a7e62","key":"2071-076320090001","value":null},
> {"id":"62a7dd81-a710-4358-9449-fcbfcccc4049","key":"2011-758220100002","value":null},
> {"id":"966ba99b-3edc-4da5-89f3-28e32edc1625","key":"2011-758220100001","value":null},
> {"id":"f15c268a-41f7-4ef3-92d2-c1516101e121","key":"2011-758220090004","value":null},
> {"id":"ac88d963-e26e-4add-8a75-5d0287feb97f","key":"2011-758220090003","value":null},
> {"id":"84abbd88-8268-4b31-a90e-31a55a137e37","key":"2011-758220090002","value":null},
> {"id":"afe0f6bb-a14f-47fa-885a-f7b9bf33f2a5","key":"2011-758220090001","value":null},
> {"id":"7d7b6733-0c62-41ab-95aa-b01cd1f5d90e","key":"2011-758220080004","value":null},
> {"id":"22afed26-2995-4ffc-92d5-b0bdb3c18849","key":"2011-758220080003","value":null},
> {"id":"ca3a81f0-017c-4680-b25c-0babd6f5afd1","key":"2011-758220080002","value":null},
> {"id":"c9fda101-fd75-4990-862f-25fc8b936d1f","key":"2011-758220080001","value":null},
> {"id":"e384832d-8378-4ab4-98c5-cf7f9ed011cd","key":"2011-758220070004","value":null}
> ]}
>
>
> When I try to recover the keys that starts with "2176-9451" I try the
> following query:
> http://homolog.webservices.scielo.org/scieloorg/_design/couchdb/_view/issue_id?startkey=["2176-9451",{}]&endkey["2176-9451"]
>
> But this query results an empty json.
>
> The result is empty even if I try a query just with the startkey:
> http://homolog.webservices.scielo.org/scieloorg/_design/couchdb/_view/issue_id?startkey=["2176-9451"]
>
> Anybody have any idea why it is not working?
>
>
> Thanks in advance,
>
> *Fabio Batalha C. Santos*
> Colegiado SciELO
> www.scielo.org
> FAPESP - CNPq - BIREME - FapUNIFESP
>

You're passing an array that has a single element that is a string.
They keys in your view are just strings (no arrays). Arrays sort after
strings, and thus your startkey sorts after everything in the view.

The query you want should be something like:

http://homolog.webservices.scielo.org/scieloorg/_design/couchdb/_view/issue_id?startkey="2176-9451"&endkey="2176-9452"&inclusive_end=false