【问题标题】:Cosmos DB SQL API query for children of nested objects嵌套对象子级的 Cosmos DB SQL API 查询
【发布时间】:2019-01-21 13:27:44
【问题描述】:
我想找到一种更好的方法来搜索集合中的文档是否具有数组中包含超过 0 个元素的属性,即任何不为空的元素。
such as: select * from c where c.property = 'x' and array_length(c.child) > 0 and array_length(c.child.grandchild) > 0
第一个数组长度有效。当我在其他地方阅读时,仅使用此点符号添加第二个不起作用。我怎样才能确保我能做到这一点。孙子将是从 0 到数组长度大于 0 的多个数字。
如果需要更多说明,请告诉我。
【问题讨论】:
标签:
azure-cosmosdb
azure-cosmosdb-sqlapi
【解决方案1】:
请使用下面的sql:
SELECT distinct c.id,c.name,c.child FROM c
join child in c.child
where array_length(c.child) > 0
and array_length(child.grandchild) > 0
我的示例文档:
[
{
"id": "1",
"name": "Jay",
"child": [
{
"name": "A",
"grandchild": [
{
"name": "A1"
},
{
"name": "A2"
}
]
},
{
"name": "B",
"grandchild": [
{
"name": "B1"
},
{
"name": "B2"
}
]
}
]
},
{
"id": "2",
"name": "Tom",
"child": [
{
"name": "A",
"grandchild": []
},
{
"name": "B",
"grandchild": []
}
]
}
]
希望对你有帮助。