Couchbase多个键
问题说明
我想一个简单的问题.我有以下数据.
I presume a simple question. I have the following data.
我想搜索ID> 2但<的所有行.8,价格> 30
I want to search for all rows where the ID is > 2 but < 8 and the Price is > 30
我使用了以下各种版本: startkey = ["2",null]
甚至是类似 startkey = ["2","30"]
的版本测试.
I have used various versions of: startkey=["2", null]
or even something like startkey=["2", "30"]
just for testing.
似乎只有在第一行同时运行这两个条件.因此,如果我这样做: startkey = ["2","30"]
,那么我会回来:
It only ever seems to run both conditions on the first row. So if I do: startkey=["2", "30"]
then I get back:
{"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}
为什么第5行在那里?
我开始认为需要在代码(.net)中进行处理并以某种方式进行多次调用...我似乎找不到任何有效的方法....
I am starting to get the view that I need to handle this in the code (.net) and make multiple calls somehow... I can't seem to find anything on this that works....
注意:我已经尝试使用 for(i = 0; i< doc.ID.length; i )
进行循环,然后使用 doc.ID [i]
,但它从不返回任何内容....
Note: I have tried doing say a loop with for (i = 0; i < doc.ID.length; i )
and then using doc.ID[i]
but it never returns anything....
目前我只有
function (doc, meta) {
emit([doc.ID, doc.Price ],null);
}
基本上,我想搜索一个用户有5个输入键的地方.所以我需要打5次电话,然后继续从上一个输出中获取数据作为下一个输出的源吗???
Essentially I want to have a search where there are 5 input keys that a user has. So do I need to make 5 calls and then keep taking data from the previous output as the source for the next???
我查看过的其他参考资料包括:手册
Other references I have looked at include: the manual
预先感谢
最亲切的问候罗宾
正确答案
这是一个常见的误解,使用复合数组索引键,仍将其视为字符串,因此索引键[2,10]实际上是"[2,10]",而索引键[5,20]实际上是"[5,20]".
This is a common misconception, with a compound array index key, it's still treated as a string, therefore the index key [2,10] is actually "[2,10]", and the index key [5,20], is actually "[5,20]".
所以 startkey = ["2","30"]
显示 {"id":"5","key":["5","20],"value":null},
行是因为作为字符串,它是>起始键.
So the reason that startkey=["2", "30"]
shows the {"id":"5","key":["5","20"],"value":null},
row is because as a string it is > startkey.
同样,查询 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}
]
}
因为 startkey ="[2,10]"
<"[2,20]" &&"[4,30]" <"[5,10]" = endkey
,但"[5,20]"不在该字符串范围内.
because startkey="[2,10]"
< "[2,20]" && "[4,30]" < "[5,10]"=endkey
, but "[5,20]" is not within that string Range.
开始键 => 结束键是使用strcmp()的范围查询,组和组级别基于字符串,其中逗号分隔字符串标记.
startkey => endkey is a Range query using strcmp(), the group and group level is based on the string, where the comma is separating string tokens.
良好的参考链接(因为Couchbase视图的工作方式与Apache CouchDB视图(受其启发)非常相似) http://wiki.apache.org/couchdb/View_collation#Collation_Specification
A Good Reference Link (since Couchbase Views work much like Apache CouchDB Views (inspired by them)) http://wiki.apache.org/couchdb/View_collation#Collation_Specification
要获得您想要的结果,您还可以编写一个Spatial View,使其具有多维查询(仅限数字).最初您可能不会想到
To achieve the result you are trying for, you could also write a Spatial View to have multi-dimensional Queries, numeric only. While you might not initially think of it
function (doc, meta) {
emit({
type: "Point",
coordinates: [doc.ID, doc.Price]
}, meta.id);
}
查询将是边界框查询:
& bbox = 2,0,8,30
&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"}
]
}
另一个查询:
& bbox = 2,30,8,30
&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"}
]
}
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhccjeig
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
检查邮件是否发送成功
it1352 07-25 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
Android微调工具-删除当前选择
it1352 06-20 -
希伯来语的空格句子标记化错误
it1352 06-22 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20