Alter all child array in document


#1

I have a document as below

{
“type”: “versions”,
“data”: {
“1.0”: [
“1.0.1”,
“1.0.2”
],
“1.1”: [
“1.1.1”,
“1.1.2”
]
}
}

need to get the out put as below

[
{
“type”: “major”,
“versionName”: “1.0”
},
{
“type”: “minor”,
“versionName”: “1.0.1”
},
{
“type”: “minor”,
“versionName”: “1.0.2”
},
{
“type”: “major”,
“versionName”: “1.1”
},
{
“type”: “minor”,
“versionName”: “1.1.1”
},
{
“type”: “minor”,
“versionName”: “1.1.2”
},
{
“type”: “major”,
“versionName”: “1.2”
}
]

Please help me


#2

Checkout Merge two child documents

SELECT  ARRAY_FLATTEN(ARRAY ARRAY_CONCAT([{"type":"major", "versionName":v.name}],
                            ARRAY {"versionName":v2,"type":"minor"} FOR v2 IN v.val END)
        FOR v IN OBJECT_PAIRS(d.data) END,1)
FROM default d WHERE type = "versions";