tags:

views:

71

answers:

1

Hello,

I have a view wich returns several elements with array keys.
Example :

{"total_rows":4,"offset":0,"rows":[
    {"id":"","key":[15,"2"],"value":1,"doc":{},
    {"id":"","key":[20,"2"],"value":1,"doc":{},
    {"id":"","key":[20,"3"],"value":1,"doc":{},
    {"id":"","key":[20,"4"],"value":1,"doc":{}
]}

I'm trying to search through those elements. So if I do the following request :

/database/_design/element/_view/all/?startkey=[15, "2"]&endkey=[20, "3"]&include_docs=true&reduce=false

Live example : http://jchris.couchone.com/keyhuh/_design/Record/_view/by_CreationDate_and_BoreholeName?startkey=[1267686720,%22sp4%22]&endkey=[1267686725,%22sp4\u9999%22]&include_docs=true&reduce=false

This one doesn't works. It returns me all the records, even the last one, which doesn't meets the second element of the array.

Strangely enough, it works with strings only.
Example :

{"total_rows":4,"offset":0,"rows":[
    {"id":"","key":["15","2"],"value":1,"doc":{},
    {"id":"","key":["20","2"],"value":1,"doc":{},
    {"id":"","key":["20","3"],"value":1,"doc":{},
    {"id":"","key":["20","4"],"value":1,"doc":{}
]}

if I do the following request :

/database/_design/element/_view/all/?startkey=["15", "2"]&endkey=["20", "3"]&include_docs=true&reduce=false

Live Example : http://jchris.couchone.com/keyhuh/_design/Record/_view/by_Client_and_BoreholeName?startkey=[%22Test1%22,%22sp4%22]&endkey=[%22Test1%22,%22sp4\u9999%22]&include_docs=true&reduce=false

Here it'll work well and only return the three first elements.

Am I missing something with couchdb's search for arrays with integers and strings ? Or have I fallen on a bug ?

Note : it does the same with CouchDB 0.10 and 0.11.

+1  A: 

This looks wrong, and there are a few things it could be. Is it possible for you to share your code with us? If the data isn't proprietary you could replicate your db to http://jchris.couchone.com/keyhuh and I'll take a look at the whole thing there.

...

Thanks for posting the live data. This is the query that is busted?

http://jchris.couchone.com/keyhuh/_design/Record/_view/by_Client_and_BoreholeName?startkey=[%22Test1%22,%22sp4%22]&endkey=[%22Test1%22,%22sp4\u9999%22]&reduce=false

Because that looks fine to me. What am I missing?

J Chris A
I've added the documents. But I can't create the views which would reproduce it. I've pasted them in a gist : http://gist.github.com/451614
Damien MATHIEU
No. It's the other one, it shouldn't display the last record as the endkey is matched.
Damien MATHIEU
Sorry, having trouble following you. What's the other one? The only thing I removed is include_docs, and it doesn't seem to make a difference.
J Chris A
Damien MATHIEU
ahh, I see (hard to make it out with the URL handling on S.O.)The problem is that yours timestamp portion of the startkey is after the sp5 key. (Arrays are sorted in element order, so the second element only matters when the first element is identical.)
J Chris A
Oh gosh how couldn't I figure that ...
Damien MATHIEU
Also... Hosted CouchDB FTW!
jhs