azure-cosmosdb - Cosmos db 查询以获取数组项不为空的数据
问题描述
我的 cosmos db 容器中有 Collection 项目。我的示例数据是
{
"objectID": "abc",
"id": "123",
"name": "gfh",
"description": "chock",
"brand": "hcn",
"size": 180,
"sizeUnits": "Grams",
"stores": []
},
{
"objectID": "123c",
"id": "0dfg",
"name": "shaek",
"description": "7ihk",
"brand": "fghcn",
"size": 768,
"sizeUnits": "Grams",
"stores": [ {
"id": 678",
"price": 2.2
},
{
"id": 678",
"price": 2.2}]
}
等等...
我需要获取存储为空的所有详细信息。如何为此编写查询。
解决方案
请尝试以下 SQL:
SELECT * FROM c where ARRAY_LENGTH(c.stores) > 0
结果:
[
{
"objectID": "123c",
"id": "0dfg",
"name": "shaek",
"description": "7ihk",
"brand": "fghcn",
"size": 768,
"sizeUnits": "Grams",
"stores": [
{
"id": 678,
"price": 2.2
},
{
"id": 678,
"price": 2.2
}
]
}
]
推荐阅读
- acumatica - 更新网格上所有行的字段
- c# - 从回测结果中寻找每日利润
- maven - 将带有分类器的工件发布到共享 pom 的 GitHub 包时,如何解决冲突?
- python - Python - 如果我不导入日志记录模块会发生日志记录
- mysql - AWS Data Pipeline - SQLActivity 到 S3 (MySQL DB)
- mysql - 如何从崩溃的 Cloud SQL 实例中保存数据而不丢失数据
- css - React.CSSProperties 用于将 css 变量插入 App 时显示解析错误
- php - 一个实体与同一个实体有 2 个多对一关系
- php - Phpunit 中具有流畅接口的模拟类
- typescript - 打字稿检查变量为空或未定义