查询CosmosDB嵌套结构JSON

时间:2019-05-09 21:08:05

标签: json azure-storage azure-cosmosdb qsqlquery azure-cosmosdb-sqlapi

我正在将CosmosDB SQLAPI用于我们的应用程序之一。我使用Azure Storage Explore查询。我发现很难查询的JSON结构。

!

我需要获取Elements [0] ID = 3,5,11,16和Elements 2 ID = 486,492

CosmosDB Quering JSON edit window

Azure Storage Explorer window trying to Query

Query working without where condition

2 个答案:

答案 0 :(得分:0)

查询嵌套数组数据时需要使用join,请尝试以下sql:

SELECT distinct c.data  from c
join elem1 in c.data[0].Elements
join elem2 in c.data[1].Elements
where elem1.ID in(3,5,6,11) and elem2.ID in (486,492)

答案 1 :(得分:0)

SQL

select value array(select value z.ID from z in a.Elements)
from c
join b in c.data
join a in b

结果

[
    [
        11,
        16,
        3,
        5
    ],
    [
        486,
        492
    ]
]