Azure Cosmos DB SQL连接和udf

时间:2019-05-17 08:38:01

标签: azure-cosmosdb

我在cosmosdb中具有以下结构

{"id": "8d4eecba-49fa-4707-979c-c9132b0c466b",
    "district": null,
    "course": null,
    "teachers": [],
    "created": "2018-08-14T14:25:41.1061235Z",
    "students": [
        "2e735887-ee17-435d-afd1-ac161ef7996e",
        "fbf477b1-bd34-42af-8b4b-876190d07aa9",
        "a4756841-2bb7-4ac1-8409-b1e382060b24",
        "29bdca72-2375-4bc5-8fc5-239f60985425",
        "eb9e456d-0407-4649-b67a-397e62339ebf",
        ],
    "teacher": "8e8bc2e7-63ad-4e27-98ed-5570d2f320ac",
    "subject": null,
    "_ts": 1555562226
}

从上面我想得到一个像下面的列表,有什么直接的方法吗?

id                                             students
8d4eecba-49fa-4707-979c-c9132b0c466b           2e735887-ee17-435d-afd1-ac161ef7996e
8d4eecba-49fa-4707-979c-c9132b0c466b           fbf477b1-bd34-42af-8b4b-876190d07aa9
8d4eecba-49fa-4707-979c-c9132b0c466b           a4756841-2bb7-4ac1-8409-b1e382060b24
8d4eecba-49fa-4707-979c-c9132b0c466b           29bdca72-2375-4bc5-8fc5-239f60985425
8d4eecba-49fa-4707-979c-c9132b0c466b           eb9e456d-0407-4649-b67a-397e62339ebf

1 个答案:

答案 0 :(得分:0)

使用sql:

Select c.id,s 
from c
join s in c.students

结果:

[
    {
        "id": "8d4eecba-49fa-4707-979c-c9132b0c466b",
        "s": "2e735887-ee17-435d-afd1-ac161ef7996e"
    },
    {
        "id": "8d4eecba-49fa-4707-979c-c9132b0c466b",
        "s": "fbf477b1-bd34-42af-8b4b-876190d07aa9"
    },
    {
        "id": "8d4eecba-49fa-4707-979c-c9132b0c466b",
        "s": "a4756841-2bb7-4ac1-8409-b1e382060b24"
    },
    {
        "id": "8d4eecba-49fa-4707-979c-c9132b0c466b",
        "s": "29bdca72-2375-4bc5-8fc5-239f60985425"
    },
    {
        "id": "8d4eecba-49fa-4707-979c-c9132b0c466b",
        "s": "eb9e456d-0407-4649-b67a-397e62339ebf"
    }
]