Couchbase多个密钥

Rob*_*ger 4 couchbase

我假设一个简单的问题.我有以下数据.

我想搜索ID> 2但<8且价格> 30的所有行

我使用过各种版本:startkey=["2", null]甚至startkey=["2", "30"]只是用于测试.

它似乎只在第一行运行两个条件.所以,如果我这样做,startkey=["2", "30"]那我就回去了:

{"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}
Run Code Online (Sandbox Code Playgroud)

为什么第5行在那里?

我开始认为我需要在代码(.net)中处理这个问题并以某种方式进行多次调用...我似乎无法找到任何有效的内容....

注意:我试过说一个循环for (i = 0; i < doc.ID.length; i++)然后使用doc.ID[i]但它永远不会返回任何东西....

目前我只是

function (doc, meta) {
    emit([doc.ID, doc.Price ],null);
}
Run Code Online (Sandbox Code Playgroud)

基本上我想要搜索一个用户有5个输入键的搜索.所以我需要进行5次调用,然后继续从前一次输出中获取数据作为下一次输出的来源???

我看过的其他参考文献包括:手册

提前致谢,

最诚挚的问候罗宾

sca*_*bl3 8

这是一个常见的误解,使用复合数组索引键,它仍然被视为一个字符串,因此索引键[2,10]实际上是"[2,10]",索引键[5,20]是实际上是"[5,20]".

所以startkey=["2", "30"]显示{"id":"5","key":["5","20"],"value":null},行的原因是因为字符串是> startkey.

同样,Query startkey=[2,10]&endkey=[5,10]返回

{"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}
  ]
}
Run Code Online (Sandbox Code Playgroud)

因为startkey="[2,10]"< "[2,20]" && "[4,30]" < "[5,10]"=endkey,但"[5,20]"不在该字符串范围内.

使用startkey和endkey进行范围查询

startkey => endkey是使用strcmp()的Range查询,组和组级别基于字符串,其中逗号分隔字符串标记.

一个很好的参考链接(因为Couchbase视图的工作方式与Apache CouchDB视图非常相似(受它们启发)) http://wiki.apache.org/couchdb/View_collat​​ion#Collat​​ion_Specification

空间视图/查询

要实现您正在尝试的结果,您还可以编写空间视图以具有多维查询,仅限数字.虽然你最初可能没想到它

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

查询将是一个边界框查询:

&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"}
]
}
Run Code Online (Sandbox Code Playgroud)

另一个问题:

&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"}
 ]
}
Run Code Online (Sandbox Code Playgroud)