Let's say I have a parent-child-grandchild-etc relationship in a Cosmos document, represented by the following JSON:
"id": "someUniqueString",
"peepsNkids": [
"Jane": [
"Joe": [],
"Jocelyn": [
"Jerry": [],
"Jan": [
"Tom": [],
"Dick": [],
"Harry": []
],
"Jim": []
],
"Mary": [
"Moe": [],
"Larry": [],
"Dorothy": [
"Eadie": [],
"Phil": [],
"Lucille": [
"Desi Jr": []
]
]
]
]
How can I query cleanly (in Storage Explorer and C#) for a subtree that, using the syntax of the "Sub-documents" section of this post titled "Query DocumentDB", would resolve to:
SELECT * FROM peepsNkids.Jane.Jocelyn.Jan
... with the expectation that the following would be returned?
[
"Tom": [],
"Dick": [],
"Harry": []
]
I don't think I need to worry about the original id here. Worst case is that I get back multiple records that have Jane.Jocelyn.Jan
, and since in my "real" setup the "names" are all unique ids, getting back multiple rows would indicate a serious schematic issue.
I can obviously create a potentially cyclical object model with string name
and List<PersonAndKids> peepsNkids
, then get back the full entry for the id "someUniqueString"
and then traverse the objects with lots of peepsNkids.TryGetValue("Jane", out firstParent)
kinds of stuff, but I'm looking for a way to do that in Cosmos rather than in my service's memory.