2

I'm new to Cosmos and I am trying to query a nested array. I found this blog on how to work with arrays but there isn't an example on a nested array.

Given this json document, how can I query the Tags array? I want to find all records that have a tag of "test-1" within its Fees array.

{
    "id": "22142846",
    "PartitionKey": 846,
    "Fees": [
        {
            "Tags": [
                "test-1"
            ]
        },
        {
            "Tags": [
                "test-2"
            ]
        }
    ]
}
2

1 Answer 1

2

Here is the sample query

SELECT c.id, c.PartitionKey
FROM c
JOIN t IN c.Fees
where array_contains(t.Tags,"test-1")

Here is the result.

enter image description here

Sample Records/Documents used

{
    "id": "22142846",
    "PartitionKey": 846,
    "Fees": [
        {"Tags": ["test-1"]},
        {"Tags": ["test-2"]}
    ]
}


{
    "id": "22142847",
    "PartitionKey": 847,
    "Fees": [
        {"Tags": ["test-1"]},
        {"Tags": ["test-2"]}
    ]
}

{
    "id": "22142848",
    "PartitionKey": 848,
    "Fees": [
       {"Tags": ["test-2"]},
       {"Tags": ["test-3"]}
    ]
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.