Arrays 在密钥数组上搜索或筛选couchdb

Arrays 在密钥数组上搜索或筛选couchdb,arrays,view,arraylist,couchdb,key,Arrays,View,Arraylist,Couchdb,Key,我的视图中有以下功能: emit([doc.address.country,doc.address.state, doc.address.city], doc); 查询搜索时,我需要填写数组的所有3个元素,例如: ?key=["US","NY","New York"] ?key=["US"] 这将生成我的记录,但比方说,我只想返回美国的所有内容,例如: ?key=["US","NY","New York"] ?key=["US"] 或者在美国和美国 ?key=["US","

我的视图中有以下功能:

emit([doc.address.country,doc.address.state, doc.address.city], doc);
查询搜索时,我需要填写数组的所有3个元素,例如:

?key=["US","NY","New York"]
?key=["US"]   
这将生成我的记录,但比方说,我只想返回美国的所有内容,例如:

?key=["US","NY","New York"]
?key=["US"]   
或者在美国和美国

?key=["US","NY"] 
或者。。。让我们说也许我想要纽约的所有唱片。。。(我知道下面的选项不起作用)


如果要将数组中的一个元素保留为空,我真的不知道如何搜索?

首先:

key=[“US”]在数组键[“US”,“NY”]上不起作用,因为您正在寻找精确的[“US”]键。相反,你必须使用

startkey=["US"]&endkey=["US",{}] 
然后,这些键位于结果集中:

["DE","Bavaria","Munich"]   <---- NO ! "DE" is out of Range of startkey
["US","FL","Miami"]         <---- YES, starts with "US"
["US","NY","New York"]      <---- YES, starts with "US"
["VE","XX","Vencuela City"] <---- NO ! "VE" is out of Range of endkey
结果:

["DE","Bavaria","Munich"]   <---- NO ! "DE" is out of Range of startkey
["US","FL","Miami"]         <---- YES, starts with "US","FL"
["US","NY","New York"]      <---- NO, "US","NY" is out of Range of endkey
["VE","XX","Vencuela City"] <---- NO ! "VE" is out of Range of endkey
查看“byCityStateCountry”:

当然,只需在第一个位置放置一个标志来确定查询的类型,这样您就可以在一个视图中完成所有操作:

emit([1,address.country,doc.address.state, doc.address.city], doc);
emit([2,doc.address.state, doc.address.city,address.country], doc);
emit([3,address.city,doc.address.state, doc.address.country], doc);
用法:

?startkey=[1,"US"]&endkey=[1,"US",{}]
?startkey=[2,"FL"]&endkey=[2,"FL",{}]
?startkey=[3,"Miami"]&endkey=[3,"Miami",{}]

注意:“左边不能有空格…”-我认为如果有降序=trues,则情况正好相反。我知道这是旧的,但也应该注意,如果键数组有很多元素,它会变得更复杂。使用这些键在视图中假设以下数据:
startkey==[a,11]和endkey=[c,11]:
[a,10],[a,11]
emit([1,address.country,doc.address.state, doc.address.city], doc);
emit([2,doc.address.state, doc.address.city,address.country], doc);
emit([3,address.city,doc.address.state, doc.address.country], doc);
?startkey=[1,"US"]&endkey=[1,"US",{}]
?startkey=[2,"FL"]&endkey=[2,"FL",{}]
?startkey=[3,"Miami"]&endkey=[3,"Miami",{}]