当Where子句数据在子数组中时,如何查询CosmosDB?

How to query CosmosDB when the Where clause data is in a subarray?

我有以下文件

{
    "id": "46c0ccbc-7a05-41dc-bc33-e9d1e69b74fa",
    "_id": "5bf8b90f9568cf0001463719",
    "vendor": "XXX",
    "updatedAt": "2018-11-26T02:17:59.311Z",
    "locales": [
        {
            "title": "351011",
            "description": " ",
            "categories": [
                "Children",
                "Accessories"
            ],
            "brand": null,
            "images": [
                "https://lp.example.com/app006prod?set=source[02_0690165_001_001],type[PRODUCT],device[hdpi],quality[80],ImageVersion[2018081]&call=url[file:/product/main]"
            ],
            "country": "SE",
            "currency": "SEK",
            "language": "en",
            "variants": [
                {
                    "artno": "example",
                    "urls": [
                        "https://www.example.com/en_sek/children/baby-newborn/product.cotton-cashmere-newborn-mittens-red.0690165001.html"
                    ],
                    "price": 120,
                    "stock": 15,
                    "attributes": {
                        "size": "One Size",
                        "color": "Burgundy"
                    }
                }
            ]
        }
    ],
    "_rid": "QEwcAOOf+rUHAAAAAAAAAA==",
    "_self": "dbs/QEwcAA==/colls/QEwcAOOf+rU=/docs/QEwcAOOf+rUHAAAAAAAAAA==/",
    "_etag": "\"00000e00-0000-0000-0000-5bfc890d0000\"",
    "_attachments": "attachments/",
    "_ts": 1543276813
}

我正在尝试编写一个简单的查询,列出所有将 "Children" 作为其类别之一的文档

我尝试了以下查询,但它不起作用

SELECT * FROM c where c.locales.categories = "Children"

我假设我错误地引用了子数组,但是编写此查询的正确方法是什么?

您需要使用ARRAY_CONTAINS功能。

试试这个:SELECT * FROM c where ARRAY_CONTAINS(c.locales[0].categories, "Children")