CosmosDB NoSQL - 过滤两个 JSON 属性以获取格式化为数字和字符串的 ID 列表

问题描述 投票:0回答:1

我正在尝试获取

Fields.FieldId
在数字列表中的行(例如:7942 到 7950)或其
Fields.ParentFieldReference
在同一数字列表中但采用字符串格式(例如:“7942”, ...,“7950”)。

我尝试了以下操作,但我只获得满足 FieldId 条件的行,而不是满足 ParentFieldReference 条件的行:

SELECT c.ID, f.FieldId, f.FieldValue, f.ParentFieldReference FROM c
JOIN f IN c.Fields
WHERE c.ID = '99999998_1_1_039075'
AND (
    f.FieldId IN (7942, 7943, 7944, 7945, 7946, 7947, 7948, 7949, 7950, 7951, 8305)
    OR ARRAY_CONTAINS(['7942', '7943', '7944', '7945', '7946', '7947', '7948', '7949', '7950', '7951', '8305'], f.ParentFieldReference, true)
)

我尝试过使用

f.ParentFieldReference IN (list)
,但仍然得到相同的结果。有谁知道我哪里错了?

样本数据如下:

{
"ID": "99999998_1_1_039075",
"Fields": [
    {
        "FieldId": 79421,
        "FieldValue": "...",
        "ParentFieldReference": "7942"
    }
]
},
{
"ID": "99999998_1_1_039075",
"Fields": [
    {
        "FieldId": 7943,
        "FieldValue": "...",
        "ParentFieldReference": null
    }
]
}
azure-cosmosdb azure-cosmosdb-sqlapi
1个回答
0
投票

尝试使用以下查询获取 79427950 之间的数字列表,或者其

Fields.ParentFieldReference
位于同一字符串格式的数字列表中("7942""7950")。

我尝试过的查询:

SELECT c.ID, f.FieldId, f.FieldValue, f.ParentFieldReference 
FROM c
JOIN f IN c.Fields
WHERE c.ID = '99999998_1_1_039075'
AND (
    (f.FieldId >= 7942 AND f.FieldId <= 7950)
    AND (f.ParentFieldReference IN ('7942', '7943', '7944', '7945', '7946', '7947', '7948', '7949', '7950'))
)

输出:

[
    {
        "ID": "99999998_1_1_039075",
        "FieldId": 7950,
        "FieldValue": "Value C",
        "ParentFieldReference": "7943"
    },
    {
        "ID": "99999998_1_1_039075",
        "FieldId": 7944,
        "FieldValue": "Value F",
        "ParentFieldReference": "7942"
    },
    {
        "ID": "99999998_1_1_039075",
        "FieldId": 7946,
        "FieldValue": "Value H",
        "ParentFieldReference": "7950"
    },
    {
        "ID": "99999998_1_1_039075",
        "FieldId": 7949,
        "FieldValue": "Value K",
        "ParentFieldReference": "7944"
    }
]
© www.soinside.com 2019 - 2024. All rights reserved.