如何使用复杂查询过滤视图

时间:2019-01-29 07:49:04

标签: couchdb couchbase-view

我正在尝试过滤发出bookName和bookItem的视图。

emit([doc.basicInfo.bookName,doc.basicInfo.bookItem],1);

它给我下面的结果,没有任何查询:

{"total_rows”:10,”offset":0,"rows":[
{"id":"d4e5548fb01e6e2c559e702fe7b138ad","key":["correctaccouts","billing"],"value":1},
{"id":"863c46c645b6344719a08231606f2a7d","key":["credeaccount","system"],"value":1},
{"id":"68d39e64c406127960dc735e8167eee3","key":["credeaccount11","system"],"value":1},
{"id":"1ab4d31588d76a42e85b526a316074de","key":["mayankamazon","billing"],"value":1},
{"id":"3204f5db5df91886373f95995ce09a2d","key":["mayankazure","asset"],"value":1},
{"id":"452c040048fb2b779205b3785615d368","key":["mayankmaaa","system"],"value":1},
{"id":"23f01f7bc60c2c8f24f6b741584a69fa","key":["TEST_AWS_Delete212sss12","asset"],"value":1},
{"id":"f0093f474e0d50f046b9fdc9145bdc91","key":["vijeth-myteam111115555555","asset"],"value":1},
{"id":"c3bce8dd1482d841f445fbd617ba1db7","key":["vijeth-myteam11111555sss5555","asset"],"value":1},
{"id":"347479ba91696b73f4a57252cd00a358","key":["vijeth-myteamOnly","asset"],"value":1}
]}

现在我正在尝试使用复杂的键对其进行查询:

satrtkey = [{},“资产”]&endkey = [{},“资产”]

它应该还给我:

{"total_rows”:5,”offset":0,"rows":[
{"id":"3204f5db5df91886373f95995ce09a2d","key":["mayankazure","asset"],"value":1},
{"id":"23f01f7bc60c2c8f24f6b741584a69fa","key":["TEST_AWS_Delete212sss12","asset"],"value":1},
{"id":"f0093f474e0d50f046b9fdc9145bdc91","key":["vijeth-myteam111115555555","asset"],"value":1},
{"id":"c3bce8dd1482d841f445fbd617ba1db7","key":["vijeth-myteam11111555sss5555","asset"],"value":1},
{"id":"347479ba91696b73f4a57252cd00a358","key":["vijeth-myteamOnly","asset"],"value":1}
]}

但是它仍然给了我全部10条记录。我只想过滤“资产”类型的记录。

1 个答案:

答案 0 :(得分:0)

要使用关键范围,必须从左字段到右字段开始缩小研究范围。

例如,如果您的密钥为:react

您可以使用[doc.basicInfo.bookItem,doc.basicInfo.bookName]

进行搜索

,您当前的查询等同于start_key=["asset",null]&end_key=["asset",{}]。相反,您应该尝试过:key=[{},"asset"],但它不起作用。

示例

查看:

start_key=[null,"asset"]&end_key=[{},"asset"]

查询:

function (doc) {
  emit([doc.basicInfo.bookItem,doc.basicInfo.bookName], 1);
}