【问题标题】:Azure CosmosDB SQL query on nested Array嵌套数组上的 Azure CosmosDB SQL 查询
【发布时间】:2019-12-08 06:06:27
【问题描述】:

我们有以下文档结构。

{
"id":"GUID",
    "customer": {
            "contacts": [
                {
                    "type": "MOBILE",
                    "status": "CONFIRMED",
                    "value": "xxxx"
                },
                {
                    "type": "EMAIL",
                    "status": "CONFIRMED",
                    "value": "aaaa"
                }
            ],
            "addresses": [
                {

                    "country": "xxx"
                }
            ]
        }
}

并且需要搜索客户->value="aaaa" 的联系人。 我尝试了以下选项

1)  SELECT c.id FROM c
    join customer in c.customer
    join contacts in c.customer.contacts
    where contacts.value = "aaaa"

2) SELECT c.id FROM c WHERE c.customer.contacts[0].value= "aaaa"

获取语法错误 400 错误请求非常感谢任何帮助

【问题讨论】:

    标签: azure-cosmosdb


    【解决方案1】:

    您的部分问题是 value 无法像搜索其他属性一样容易。以下是可能的解决方案:

    SELECT c.id FROM c
    join contacts in c.customer.contacts where contacts["value"] = "aaaa"
    
    SELECT c.id FROM c WHERE c.customer.contacts[1]["value"] = "aaaa"
    
    

    Document DB SQL Api - unable to query json property with name 'value' and its value is integer

    【讨论】:

    • 感谢@AlexAIT,您的查询很有魅力。我不知道限制,JSON 属性名称 - '值'。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多