如何进行多个 IN ["V1", "V3","V5"] 查询

How to make multiple IN ["V1", "V3","V5"] query

对于具有以下结构的文档

{
  "countryCode": "US",
  "status" : "Pending"
}

其中 countryCode 的选项列表有限(ISO 国家/地区代码) status 也有一组有限的选项,我只需要 select 那些文件 基本上是针对给定的国家列表和给定的状态列表

在SQL中意味着它会像

countryCode IN ["US","AR", "UK"] AND status IN ["Pending", "Error", "Loading"]

在 Cloudant / CouchDB 中完全可行吗?

使用 CouchDB 的 /db/_find, the following selector 产生了期望的结果:

{
   "selector":{
      "$and":[
         {
            "countryCode":{
               "$in":["US", "AR", "UK"]
            }
         },
         {
            "status":{
               "$in":["Pending", "Error", "Loading"]
            }
         }
      ]
   }
}

Condition operators such as $in are specific to a field, and are used to evaluate the value stored in that field.

CURL

curl -H 'Content-Type: application/json' -X POST http://localhost:5984/<db>/_find -d '{"selector":{"$and":[{"countryCode":{"$in":["US", "AR", "UK"]}},{"status":{"$in":["Pending", "Error", "Loading"]}}]}}'