We persist Cosmos documents with a tree of nodes that can have an unbounded depth, e.g. children have arrays of children who have arrays of children etc etc.
We need to query the document and flatten all properties of a given name (queryRef) from all levels in the tree.
This is the persisted document:
{
id: "1",
children: [
{
id: "2",
queryRef: {ref: "a"},
children: [
{
id: "3",
queryRef: {ref: "b"},
children: [
{
id: "5",
queryRef: {ref: "c"},
children: [
...
]
}
]
},
...
]
}
]
}
This is the desired response:
{
id: "1",
queryRefs: [
{
ref: "a",
},
{
ref: "b",
},
{
ref: "c",
}
]
}
With a query along the lines of:
SELECT c.id, c.children[...].queryRef FROM c