Hi,
I am trying to get the child and parent record of a document. This is the scenario that I am trying to achieve.
Let’s say that I have a document with the following structure:
Meta ID: DOC1
{
"a": {
"attra": "attra-value",
"b": [
{
"attrb": "attrb-value",
"c": [
{
"attrc": "attrc-value",
"d": [
{
"attrd": "attrd-value",
"e": [
{
"attr1": "attr1 - value1",
"attr2": "attr2 - value1",
"attr3": "attr3 - value1"
},
{
"attr1": "attr1 - value2",
"attr2": "attr2 - value2",
"attr3": "attr3 - value2"
},
{
"attr1": "attr1 - value3",
"attr2": "attr2 - value3",
"attr3": "attr3 - value3"
}
],
"f": {
"g": [
{
"gattr1": "attr1 - value1",
"gattr2": "attr2 - value1",
"gattr3": "attr3 - value1"
},
{
"gattr1": "attr1 - value2",
"gattr2": "attr2 - value2",
"gattr3": "attr3 - value2"
},
{
"gattr1": "attr1 - value3",
"gattr2": "attr2 - value3",
"gattr3": "attr3 - value3"
}
]
}
}
]
}
]
}
]
}
}
Now I want the whole document but from array “e”, I just need the json object having the value of “attr1” and from “g” array I need the json object having the value of “gattr1”
This is what I need.
{
"a": {
"attra": "attra-value",
"b": [
{
"attrb": "attrb-value",
"c": [
{
"attrc": "attrc-value",
"d": [
{
"attrd": "attrd-value",
"e": [
{
"attr1": "attr1 - value1"
},
{
"attr1": "attr1 - value2"
},
{
"attr1": "attr1 - value3"
}
],
"f": {
"g": [
{
"gattr1": "attr1 - value1"
},
{
"gattr1": "attr1 - value2"
},
{
"gattr1": "attr1 - value3"
}
]
}
}
]
}
]
}
]
}
}
How can I achieve this via sub doc api or n1ql for the meta id DOC1
Thanks,
Himanshu