0
votes

Say I have these 3 documents in a DocumentDB collection:

[
    {
        "name": "tiger",
        "keywords": [
            "animal",
            "cat",
            "stripes"
        ]
    },
    {
        "name": "cat"
    },
    {
        "keywords": [
            "panther",
            "black"
        ]
    }
]

How would I structure a single SQL query to return all documents where the 'name' matches "cat" OR a 'keyword' matches "cat" when 'keywords' and 'name' are optional elements in the document?

1

1 Answers

1
votes

Try this query:

SELECT * FROM root r WHERE r.name = 'cat' OR ARRAY_CONTAINS(r.keywords, 'cat')