MrPJ
MrPJ

Reputation: 31

Get objects fields values from array in CosmosDB

I have a query for CosmosDB:

SELECT food.tags FROM food

which returns this:

{
  "tags": [
    {
      "name": "babyfood"
    },
    {
      "name": "dessert"
    },
    {
      "name": "fruit pudding"
    },
    {
      "name": "orange"
    },
    {
      "name": "strained"
    }
  ]
}

I would like to create a query to obtain results like:

["babyFood", "dessert", "fruit pudding", "orange", "strained"] 

so my goal is to get an array which will contain values of 'name' field from all objects in 'tags' array.

How could it be done in CosmosDB SQL?

Please help.

Upvotes: 3

Views: 2837

Answers (1)

juwil
juwil

Reputation: 466

SELECT VALUE t.name from f join t in food.tags

with VALUE you do the flattening.

Upvotes: 6

Related Questions