Documents DocumentDB Query, where Array_Length> 1

I have sets of documents that look like this:

[
  {
    "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
  }
]

I need to request any documents in which the array Property1in node properties has more than 1 element. In my example above, I would expect to return only Document1and Document3. I spent a lot of time experimenting with the Array_Contains syntax, but keep lagging. Here's what my last attempt looks like:

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

But with my syntax, I return every document.

+4
source share
1 answer

You will need the following query:

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

, DocumentDB , , d.Properties.Property1, d.Properties.Property1 [0] .., .

+5

Source: https://habr.com/ru/post/1650856/


All Articles