Startkey & endkey : strange result


#1

Hello,

I’m trying to get a view with startkey and endkey parameters but i’ve strange results.

My view :

function (doc, meta) {
emit([doc.id, doc.request_time], { “id” : doc.id, “group” : doc.group, “message”:doc.message, “level”: doc.level, “url”:doc.url, “sbt”:doc.sbt, “request_time”:doc.request_time, “site_id”:doc.site_id });
}

doc.id = 28
doc.request_time = 1272817191 (timestamp)

and the query :

_view/by_time?stale=false&startkey=[24%2C+1]&endkey=[31%2C+1272817191]&connection_timeout=60000&limit=10&skip=0

startkey=[24, 1]
endkey= [31, 1272817191]

In fact, i want docs which their id > x et request_time < x. I have trouble to do this, so i try to do id >24 and <31 and request_time >1 and < 1272817191. Look the result (i just put keys result) :

[25,1372837191]
[26,1372817191]
[27,1372817191]
[28,1372817191]
[29,1172817191]
[30,1072817191]

I don’t understand why 25, 26, 27, 28 are return…

Thanks for helping


#2

Couchbase has only one index. So you can’t filter by two ranges. See this for more detailed answer:

PS. May be it’s a good idea to add such question to some FAQ.


#3

Ok, i understand.

So can i do a endkey=126782 and startkey_docid= 21 to have all documents which have a request_time less than 126782 and the id greater than 21 ?


#4

But if you have sequential ids and you have all docs before doc with id=21 you can try to use skip param to skip previous 20 docs and start from doc_id=21.


#5

Oh, I don’t know. Param startkey_docid never worked for me and I don’t know if it works at all :).