Thomas Segato
Thomas Segato

Reputation: 5221

Query cosmos db siblings with no childs

Is it possible to query cosmos db without returning child? I want following result:

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

From following:

{
    "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"
                }
            ]
        }
    ]
}

I would prefer it without trigger so pure select.

Upvotes: 1

Views: 50

Answers (1)

Jay Gong
Jay Gong

Reputation: 23782

Just use join keyword :

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

Output:

enter image description here

Upvotes: 1

Related Questions