DocumentDB查询文档中的子元素

时间:2017-11-16 11:12:52

标签: azure azure-cosmosdb

在下面的DocumentDB文档中,查询DevicePin的正确方法是什么?即WHERE DevicePin =' 1234' 我使用Node.js并使基本查询正常工作,我可以查询电子邮件和名称之类的内容,只是无法获得DevicePin的语法正确

{
    "id": "2ca572d0-858d-4376-8537-c228a8379638",
    "Email": "dave@test.com",
    "Name": "dave",
    "OrgRoles": null,
    "DeviceIDs": [
        {
            "DeviceID": "12121212",
            "DevicePin": "1234"
        }
    ],
    "UpdatedDate": "2017-11-10T13:18:32.0110724Z",
    "CreatedDate": "2017-11-10T13:18:27.220764Z",
    "IsDeleted": true,
    "_rid": "kIddAMqgTQBFAAAAAAAAAA==",
    "_self": "dbs/kIddAA==/colls/kIddAMqgTQA=/docs/kIddAMqgTQBFAAAAAAAAAA==/",
    "_etag": "\"02007530-0000-0000-0000-5a0d685b0000\"",
    "_attachments": "attachments/",
    "_ts": 1510828123
}

2 个答案:

答案 0 :(得分:0)

知道了,以防其他人想要这样做:

SELECT * 
FROM c.DeviceIDs[0] d 
WHERE (d.DevicePin = "1234")

答案 1 :(得分:0)

如果您不知道数组元素编号,则可以使用

 SELECT * FROM c WHERE 
    array_contains(c.DeviceIDs, {"DevicePin": "1234"})