如何 SQL 查询 MS Azure CosmosDB 中的嵌套列表和数组?

How to SQL query a nested list and array in a MS Azure CosmosDB?

我有以下 (Azure) CosmosDB(子)结构,它有 2 个嵌套数组:

{
    "id": "documentTypes",
    "SomeThing": "SomeThing",
    "configuration": [
        {
            "language": "en",
            "list": [
                {
                    "id": 1,
                    "name": "Supporting Documents"
                },
                {
                    "id": 2,
                    "name": "Summary PDF"
                },
            ]
        }
    ],
}

我尝试了以下查询,但结果很差。

SELECT * FROM c WHERE c.documentTypes.configuration[0].list[0].id FROM c

SELECT
    p.id,       
    p.name
FROM f
    JOIN c IN f.configuration
    JOIN p IN c.list
WHERE c.id == 'documentTypes'

Q: 如何只获取nameid的列表?

你需要这个吗?

SELECT ARRAY(SELECT VALUE e FROM c JOIN d IN c["configuration"] JOIN e IN d["list"]) AS Result FROM c

输出:

[ { "Result": [ { "id": 1, "name": "Supporting Documents" }, { "id": 2, "name": "Summary PDF" } ] } ]

我自己的解决方案类似于 Sajeetharan 的解决方案:

SELECT list.id, list.name FROM c
    JOIN configuration IN c.configuration 
    JOIN list IN configuration.list
WHERE c.id = 'documentTypes'

这对我来说看起来更简单一些,因为不需要 [""]ARRAY() 函数,而且不会产生额外的 Result 项目。我不知道是否有任何性能差异。