Mark Chidlow
Mark Chidlow

Reputation: 1472

How to merge child arrays of documents in Document DB database?

I am using Azure DocumentDB NoSQL database with an ASP.NET MVC front end.

I have a Families collection (just as an example):

[
    {
        "FamilyName": "Smith",
        "Children": [
            {
                "FirstName": "John"
            },
            {
                "FirstName": "Mike"
            }
        ]
    },
    {
        "FamilyName": "Williams",
        "Children": [
            {
                "FirstName": "Mark"
            },
            {
                "FirstName": "Mark"
            },
            {
                "FirstName": "Peter"
            }
        ]
    }
]

Is there a way that I can retrieve a list of "Children" (e.g. List) in alpha order without looping through each family and building a separate list?

Upvotes: 0

Views: 431

Answers (1)

Mikhail Shilkov
Mikhail Shilkov

Reputation: 35154

That's what JOIN is used for:

SELECT c.FirstName
FROM Families f 
JOIN c IN f.children 
ORDER BY c.FirstName ASC

Upvotes: 1

Related Questions