sql - 如何在 CosmosDB SQL 中查询嵌套数组中的字段
问题描述
parameter.code = "123"
在给定此文档结构的情况下,如何使用 CosmosDB SQL 查询返回所有具有的文档?有必要使用UDF吗?(如果有,怎么做?)
{
"batch_id": "abc",
"samples": [
{
"sample_id": "123",
"tests": [
{
"parameter": {
"code": "123", // <- target
}
}
]
}
]
}
解决方案
无需使用 UDF(用户定义函数),只需使用 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"
输出: