2 years ago
#71351
Krumelur
Cosmos DB: how to project properties into array and group them?
Using this sample data consisting of 3 separate documents in the same container:
{
"id" : "doc1",
"manager" : "John",
"country": "Germany"
}
{
"id" : "doc2",
"manager" : "John",
"country": "Netherlands"
}
{
"id" : "doc3",
"manager" : "Jack",
"country": "Austria"
}
I would like to write a query that returns a list of objects containing the distinct manager names and the countries they're responsible for. Something in the shape of:
[
{
"manager": "John",
"countries": ["Germany", "Netherlands"]
},
{
"manager": "Jack",
"countries": ["Austria"]
}
]
I have tried (and failed) with joins, subqueries, and JSON object projections.
azure-cosmosdb
azure-cosmosdb-sqlapi
0 Answers
Your Answer