DocumentDB查询文档,其中Array_Length> 1

INN*_*VTV 14 azure azure-cosmosdb

我有几组文档如下:

[
  {
    "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
  }
]
Run Code Online (Sandbox Code Playgroud)

我需要查询Property1Properties节点中的数组有多于1个项目的任何文档.在我上面的例子我希望只拿回Document1Document3.我花了很多时间尝试使用Array_Contains语法,但一直在做空.这是我最近的尝试:

SELECT * FROM Docs d WHERE ARRAY_LENGTH([d.Properties, 'Property1']) > 1
Run Code Online (Sandbox Code Playgroud)

但是根据我的语法,我会收回所有文档.

Ara*_* R. 22

您需要如下查询:

SELECT * FROM Docs d WHERE ARRAY_LENGTH(d.Properties.Property1) > 1
Run Code Online (Sandbox Code Playgroud)

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

  • 我想通了:SELECT*FROM Docs d WHERE ARRAY_LENGTH(d.Properties ["Property 1"])> 1 (2认同)