Yashashwi
Yashashwi

Reputation: 1

Flatten a document in document db

I have a document in document db that has a property that is an array of an object. I would like to flatten it and get a single property in all the objects in terms of an array.

eg:

{
    "name" : "blah",
    "address" : [
        {
           "type" : "home",
           "location" : "123 st"
        },
        {
           "type" : "work",
           "location" : "321 st"
        }
    ]
}

-> What I want

[
    {
       "name" : "blah",
       "locations" : [ "123 st", "321 st" ]
    }

]

Upvotes: 0

Views: 671

Answers (1)

Fei Han
Fei Han

Reputation: 27793

You could try to define and use User-defined function to extract locations info.

enter image description here

And then you could call this User-defined function from inside your query.

enter image description here

Upvotes: 1

Related Questions