DocumentDB 查询文档 Array_Length > 1

DocumentDB Query documents where Array_Length > 1

我有几组文档如下所示:

[
  {
    "Name": "Document1",
    "Properties": {
      "Property1": [
        "Value1",
        "Value2",
        "Value3",
      ]
    },
    "Tags": null
  },
  {
    "Name": "Document2",
    "Properties": {
      "Property1": [
        "Value1",
      ]
    },
    "Tags": null
  },
  {
    "Name": "Document3",
    "Properties": {
      "Property1": [
        "Value1",
        "Value2",
      ]
    "Property2": [
        "Value1",
      ]
    },
    "Tags": null
  }
]

我需要查询 Properties 节点中 Property1 数组包含超过 1 项的任何文档。在我上面的示例中,我希望只返回 Document1Document3。我花了很多时间来试验 Array_Contains 语法,但总是很短。这是我最近的尝试:

SELECT * FROM Docs d WHERE ARRAY_LENGTH([d.Properties, 'Property1']) > 1

但是使用我的语法我可以返回每个文档。

您需要如下查询:

SELECT * FROM Docs d WHERE ARRAY_LENGTH(d.Properties.Property1) > 1

请注意,DocumentDB 的语法适用于分层嵌套数据,您可以像在编程语言中一样访问 d.Properties.Property1、d.Properties.Property1[0] 等属性。