首页 > 解决方案 > 如何在 CosmosDB SqlAPI 中使用破折号查询属性?

问题描述

查询:我想获取所有在 3 月份出生的人的记录列表。

{
    "details": {
        "state": "CA",
        "city": "San Fransisco",
        "date-of-birth": { // there is a "-" in the key
            "month": "March",
            "year": "2000"
        }
    },
    "personId": "person1",
    "id": "id1"
},
{
    "details": {
        "state": "CA",
        "city": "San Jose",
        "date-of-birth": { // there is a "-" in the key
            "month": "April",
            "year": "2000"
        }
    },
    "personId": "person2"
    "id": "id2"
}

我希望 SQL 查询会是这样的,但出现错误:

select * from c where c.details['date-of-birth'['month']] = "March"

有人可以帮我查询吗?我确实尝试查看文档,但有点困惑。

标签: azureazure-cosmosdbazure-cosmosdb-sqlapi

解决方案


尝试这个

select * from c where c.details['date-of-birth'].month = "March"

推荐阅读