【问题标题】:Query cosmos db siblings with no childs查询没有子节点的 cosmos db 兄弟节点
【发布时间】:2020-02-14 16:23:29
【问题描述】:

是否可以在不返回子项的情况下查询 cosmos db?我想要以下结果:

[{"groupId":1,"name":"group1"},{"groupId":2,"name":"group2"}]

来自以下:

{
    "groups":
    [
        {
            "groupId":1,
            "name":"group1",
            "subgroups":
            [
                {
                    "subGroupId":1,
                    "name":"subgroup1"
                },
                {
                    "subGroupId":2,
                    "name":"subgroup2"
                }
            ]
        },
        {
            "groupId":2,
            "name":"group2",
            "subgroups":
            [
                {
                    "subGroupId":1,
                    "name":"subgroup1"
                },
                {
                    "subGroupId":2,
                    "name":"subgroup2"
                }
            ]
        }
    ]
}

我更喜欢没有触发器的,那么纯粹的选择。

【问题讨论】:

    标签: azure-cosmosdb


    【解决方案1】:

    只需使用 join 关键字:

    SELECT g.groupId,g.name FROM c
    join g in c.groups
    

    输出:

    【讨论】:

    • 确实如此。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-18
    • 1970-01-01
    • 2014-02-05
    • 1970-01-01
    • 1970-01-01
    • 2010-10-24
    相关资源
    最近更新 更多