gpt4 book ai didi

azure-cosmosdb - 针对嵌套对象的子对象的 Cosmos DB SQL API 查询

转载 作者:行者123 更新时间:2023-12-02 03:31:05 25 4
gpt4 key购买 nike

我想找到一种更好的方法来搜索集合中的文档是否具有数组中包含超过 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 的多个数字。

如果需要更多说明,请告诉我。

最佳答案

请使用以下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": []
}
]
}
]

希望对您有帮助。

关于azure-cosmosdb - 针对嵌套对象的子对象的 Cosmos DB SQL API 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51845658/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com