Couchbase 查询数组

Couchbase query array

我有以下 json 保存在我的 couchbase 存储桶中 "geo"

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {
        "ID": "1753242",
        "TYPE": "8003"
      }
    },
    {
      "type": "Feature",
      "properties": {
        "ID": "4823034",
        "TYPE": "7005"
      }
    },
    {
      "type": "Feature",
      "properties": {
        "ID": "4823034",
        "TYPE": "8003"
      }
    }
  ]
}

为了获得所有 "features""properties.TYPE : 8003" 我尝试了以下方法。

SELECT features FROM geo
WHERE ANY f IN features SATISFIES f.properties.TYPE = "8003" END;

但这 returns 整个 json 文档,而不仅仅是 "features"properties.TYPE "8003"。 有谁知道,如何查询以得到结果为 "properties.TYPE": "8003" 的匹配特征?

WHERE 子句中的 ANY 表达式用于仅过滤感兴趣的文档。如果你想要具体的项目列表,你也需要在投影列表中写上相应的表达式。您查询中的投影要求 'features',因此将返回整个 'features' 数组。您可以在投影列表中写入以下表达式以获得您想要的输出:

SELECT ARRAY f FOR f IN features WHEN f.properties.TYPE = "8003" END
FROM geo
WHERE ANY f IN features SATISFIES f.properties.TYPE = "8003" END;
[
  {
    "": [
      {
        "properties": {
          "ID": "1753242",
          "TYPE": "8003"
        },
        "type": "Feature"
      },
      {
        "properties": {
          "ID": "4823034",
          "TYPE": "8003"
        },
        "type": "Feature"
      }
    ]
  }
]

hth,

-普拉萨德