简体   繁体   English

如何在此 CosmosDB 查询中获取 value 属性?

[英]How do I get the value property in this CosmosDB QUery?

I am trying to get deeper into an object but for some reason it does not work in my Cosmos query, the query is quite simple as follows.我试图更深入地了解一个对象,但由于某种原因它在我的 Cosmos 查询中不起作用,查询非常简单,如下所示。

SELECT c.id,  
c.ItemNo, 
bv.variantId AS variantNo, 
bv.variantDescription AS title, 
c.BasicData.presentation.articleLongDescription[0] AS Description,
c.BasicData.presentation.articleCompositionList.origin,
bv.size.sizeName,
c.BasicData.asset.assets[0].locations[1].path
FROM c
JOIN bv IN c.BasicData.base.sales.variants
WHERE c.brand = 'XXX'
AND c.Consumer = 'XXX'
AND bv.variantId = 'XXX'
AND c.Season = 'XXX'

The result is rather straight forward too as follows结果也相当直接,如下

[
    {
        "id": "9c9c5b56-999f-4f98-8c52-902f43dd4cfe",
        "ItemNo": "0562168014",
        "variantNo": "0562168014003",
        "title": "Trousers Grey, 36",
        "Description": {
            "locale": "en-GB",
            "value": "jongel fibbel"
        },
        "origin": "{\"\":{\"materials\":{\"002elastane\":\"30.0\",\"002polyester\":\"70.0\"}}}",
        "path": "https://public.assets.XXX.com/assets/002/b0/1b/b01b4fa77023f48ca3c6ff8777cc27276f478f1e.jpg"
    }
]

My problem is I want to return the "value" property "jongel fibbel" instead of the entire description object我的问题是我想返回“值”属性“jongel fibbel”而不是整个描述对象

I tried changing我试着改变

c.BasicData.presentation.articleLongDescription[0] AS Description,

To

c.BasicData.presentation.articleLongDescription[0].value AS Description,

But that gives me a syntax error at value但这给了我一个语法错误的价值

How can I return the value properly in the above query?如何在上述查询中正确返回值?

EDIT -------编辑 - - - -

aricleLongDescription is an array as follows

"articleLongDescription": [
                {
                    "locale": "en-GB",
                    "value": "jongel fibbel"
                }
            ],

SO I also tried JOIN as follows所以我也试过 JOIN 如下

SELECT c.id,  
c.ItemNo, 
bv.variantId AS variantNo, 
bv.variantDescription AS title, 
ba.value AS Description,
c.BasicData.presentation.articleCompositionList.origin,
bv.size.sizeName,
c.BasicData.asset.assets[0].locations[1].path
FROM c
JOIN bv IN c.BasicData.base.sales.variants
JOIN ba IN c.BasicData.presentation.articleLongDescription
WHERE c.brand = 'XXX'
AND c.Consumer = 'XXX'
AND bv.variantId = 'XXX'
AND c.Season = 'XXXX'

But it also fails with syntax error at value但它也因语法错误而失败

EDIT ---编辑 - -

Also tried a subquery as follows还尝试了如下子查询

SELECT c.id,  
c.ItemNo, 
bv.variantId AS variantNo, 
bv.variantDescription AS title, 
--c.BasicData.presentation.articleLongDescription[0] AS Description,
-- ARRAY(SELECT serving.description FROM serving IN food.servings) AS servings
ARRAY(SELECT jongel.value FROM jongel IN c.BasicData.presentation.articleLongDescription) AS Description

c.BasicData.presentation.articleCompositionList.origin,
bv.size.sizeName,
c.BasicData.asset.assets[0].locations[1].path
FROM c
JOIN bv IN c.BasicData.base.sales.variants
JOIN ba IN c.BasicData.presentation.articleLongDescription
WHERE c.brand = 'XXX'
AND c.Consumer = 'XXX'
AND bv.variantId = 'XXX'
AND c.Season = 'XXX'

But it also fails with syntax error at value, I am wondering is "value" a protected keyword or something in CosmosDB?但它也因 value 的语法错误而失败,我想知道“value”是受保护的关键字还是 CosmosDB 中的某个东西?

As it turns out value is a reserved keyword in CosmosDB so the syntax to get around that is as follows事实证明 value 是 CosmosDB 中的保留关键字,因此绕过它的语法如下

c.BasicData.presentation.articleLongDescription[0]["value"] AS Description,

Note there is no .(dot) just brackets and doublequotes注意没有 .(dot) 只是括号和双引号

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 CosmosDB 获取文档属性为小写但 model 属性为大写的项目? - How do I get items from CosmosDB where the document property is lowercase, but the model property is uppercase? 如何在 CosmosDB 中为 ST_WITHIN 调用空间查询 - How do I call a spatial query in CosmosDB for ST_WITHIN 如何使用反射获取属性并在查询中使用它? - How do I use reflection to get a property and use it in a query? 如何以编程方式获取 NotifyIcon.Icon 属性的值? - How do I get the value of NotifyIcon.Icon property programmatically? 如何在 CosmosDB 中向 SqlParameter 提供 JSON 片段作为值 - How can I provide an JSON fragment as an value to SqlParameter in CosmosDB 如何在CosmosDB实例中使用mongodb的分片 - How do I use mongodb's sharding in a CosmosDB instance 对于 CosmosDB,如何将日期值转换为 YYYY-MM-DDThh:mm:ss.sssZ 格式的字符串? - How can I get the value of a date into a string in the format YYYY-MM-DDThh:mm:ss.sssZ for CosmosDB? 如何从CosmosDB中的现有容器获取带有索引的ContainerProperty - How can I get the ContainerProperties with Indexes from an existing container in CosmosDB 我如何使用财产{get; }? - how do i use a property { get; }? 如何获得自定义属性的值? - How can i get the value of the custom property?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM