如何通过连接在 CosmosDB 中创建 select * 查询?

How can I make a select * query work in CosmosDB with a join?

我有类似的文件

{
    "id": "XX",
    "_id": "XX",
    "artno": "0107727021",
    "vendor": "XX",
    "updatedAt": "2019-06-24T20:25:49.602Z",
    "locales": [
        {
            "title": "Bademantel aus Leinen",
            "description": "PREMIUM QUALITÄT. Bademantel aus gewaschenem Leinen mit zwei Vordertaschen und einem Bindegürtel in der Taille. Unisex. Durch Trocknen im Wäschetrockner bleibt die Weichheit des Leinens erhalten.",
            "categories": [
                "Damen",
                "Nachtwäsche",
                "Nachthemden & Morgenmäntel",
                "Bademantel"
            ],
            "brand": "XX",
            "country": "DE",
            "currency": "EUR",
            "language": "de",
            "variants": [
                {
                    "artno": "0107727021002",
                    "price": 39.99,
                    "stock": 1,
                    "attributes": {
                        "size": "S/M",
                        "color": "Grau"
                    }
                },
                {
                    "artno": "0107727021004",
                    "price": 39.99,
                    "stock": 0,
                    "attributes": {
                        "size": "L/XL",
                        "color": "Grau"
                    }
                }
            ]
        },
        {
            "title": "Morgonrock i tvättat linne",
            "description": "PREMIUM QUALITY. En morgonrock i tvättat linne. Morgonrocken har två framfickor och knytskärp i midjan. Unisex. Torktumla gärna för att behålla mjukheten i linnet.",
            "categories": [
                "Dam",
                "Sovplagg",
                "Nattlinnen & Morgonrockar",
                "Morgonrock"
            ],
            "brand": "XX",
            "country": "SE",
            "currency": "SEK",
            "language": "sv",
            "variants": [
                {
                    "artno": "0107727021002",
                    "price": 399,
                    "stock": 1,
                    "attributes": {
                        "size": "S/M",
                        "color": "Grå"
                    }
                },
                {
                    "artno": "0107727021004",
                    "price": 399,
                    "stock": 0,
                    "attributes": {
                        "size": "L/XL",
                        "color": "Grå"
                    }
                }
            ]
        }
    ]
}

我想查询并获取所有文档,但仅使用数组中指定国家/地区是我正在过滤的部分的数据。

例如 country = 'DE' 那么我想要的文档只有数组的那一部分而不是所有国家信息

我尝试了以下查询,但它告诉我我不能使用 select *

SELECT * FROM c join l in c.locales where l.country = 'DE'

那么我该怎么做才能完成这项工作?

错误提示'SELECT *' is only valid with a single input set.

您的sql使用JOIN,所以请定义您要查询的具体列:

SELECT c.XX,c.YY,l.ZZ FROM c
 join l in c.locales 
 where l.country = 'DE'

或直接使用c

SELECT c FROM c
 join l in c.locales 
 where l.country = 'DE'

请调整你的sql喜欢:

SELECT l FROM c
 join l in c.locales 
 where l.country = 'DE'

输出:

[
    {
        "l": {
            "title": "Bademantel aus Leinen",
            "description": "PREMIUM QUALITÄT. Bademantel aus gewaschenem Leinen mit zwei Vordertaschen und einem Bindegürtel in der Taille. Unisex. Durch Trocknen im Wäschetrockner bleibt die Weichheit des Leinens erhalten.",
            "categories": [
                "Damen",
                "Nachtwäsche",
                "Nachthemden & Morgenmäntel",
                "Bademantel"
            ],
            "brand": "XX",
            "country": "DE",
            "currency": "EUR",
            "language": "de",
            "variants": [
                {
                    "artno": "0107727021002",
                    "price": 39.99,
                    "stock": 1,
                    "attributes": {
                        "size": "S/M",
                        "color": "Grau"
                    }
                },
                {
                    "artno": "0107727021004",
                    "price": 39.99,
                    "stock": 0,
                    "attributes": {
                        "size": "L/XL",
                        "color": "Grau"
                    }
                }
            ]
        }
    }
]