Numerous Couchbase Keys

I guess a simple question. I have the following data.

I want to find all rows where id is β†’ 2 but <8 and price is β†’ 30

I used different versions: startkey=["2", null] or even something like startkey=["2", "30"] just for testing.

It seems that in the first row both conditions are satisfied. Therefore, if I do this: startkey=["2", "30"] , then I will return:

 {"id":"3","key":["3","30"],"value":null}, {"id":"4","key":["4","30"],"value":null}, {"id":"5","key":["5","20"],"value":null}, {"id":"6","key":["6","60"],"value":null}, {"id":"8","key":["8","60"],"value":null} 

Why is line 5 there?

I am starting to get the idea that I need to process this in code (.net) and make some calls somehow ... I cannot find anything on this that works ...

Note. I tried to loop with for (i = 0; i < doc.ID.length; i++) and then using doc.ID[i] , but it never returns anything ....

I'm just now

 function (doc, meta) { emit([doc.ID, doc.Price ],null); } 

Essentially, I want to have a search in which there are 5 input keys that the user has. So I need to make 5 calls, and then continue to take data from the previous output as a source for the next ???

Other links I reviewed include: manual

Thanks in advance,

Regards Robin

+4
source share
1 answer

This is a common misconception that contains the key index of a compound array, it is still considered a string, so the index key [2,10] is actually "[2,10]" and the index key [5,20] is actually " [5.20]. "

Thus, the reason why startkey=["2", "30"] shows the line {"id":"5","key":["5","20"],"value":null}, , is that as a string this is> startkey.

Similarly, the query startkey=[2,10]&endkey=[5,10] returns

 {"total_rows":7,"rows":[ {"id":"2","key":[2,20],"value":null}, {"id":"3","key":[3,30],"value":null}, {"id":"4","key":[4,30],"value":null} ] } 

because startkey="[2,10]" < "[2,20]" && "[4,30]" "[5,10]"=endkey , but "[5,20]" is not within this range of rows.

Range Queries with Start Key and End Key

startkey => endkey is a range query using strcmp (), the group and group level is based on the line where the comma separates the character characters.

Good Link Link (since Couchbase Views works just like Apache CouchDB Views (inspired by them)) http://wiki.apache.org/couchdb/View_collation#Collation_Specification

Spatial View / Query

To achieve the result you are trying to do, you can also write a spatial view to have multidimensional queries, only numerical. Although you cannot initially think about it

 function (doc, meta) { emit({ type: "Point", coordinates: [doc.ID, doc.Price] }, meta.id); } 

The request will be a bounding block request:

& BBOX = 2,0,8,30

 {"total_rows":0,"rows":[ {"id":"2","bbox":[2,20,2,20],"geometry":{"type":"Point","coordinates":[2,20]},"value":"2"}, {"id":"3","bbox":[3,30,3,30],"geometry":{"type":"Point","coordinates":[3,30]},"value":"3"}, {"id":"4","bbox":[4,30,4,30],"geometry":{"type":"Point","coordinates":[4,30]},"value":"4"}, {"id":"5","bbox":[5,20,5,20],"geometry":{"type":"Point","coordinates":[5,20]},"value":"5"} ] } 

Another request:

& BBOX = 2.30.8.30

 {"total_rows":0,"rows":[ {"id":"3","bbox":[3,30,3,30],"geometry":{"type":"Point","coordinates":[3,30]},"value":"3"}, {"id":"4","bbox":[4,30,4,30],"geometry":{"type":"Point","coordinates":[4,30]},"value":"4"} ] } 
+8
source

All Articles