0
votes

How can I return all documents which have parameter.code = "123", given this document structure, using CosmosDB SQL query? Is it necessary to use a UDF? (If so, how?)

{
    "batch_id": "abc",
    "samples": [
        {
            "sample_id": "123",
            "tests": [
                {
                    "parameter": {
                        "code": "123", // <- target
                    }
                }
            ]
        }
    ]
}
1

1 Answers

1
votes

No need to use UDF(User Defined Function),just use cosmos db query sql with double JOIN.

SQL:

SELECT c.batch_id FROM c
join samples in c.samples 
join tests in samples.tests
where tests.parameter.code = "123"

Output:

enter image description here