Used default bucket
create index ix50 on default(_id) WHERE _type = "question";
UPSERT INTO default VALUES("a53ae3bc-654c-4d9d-a6aa-62e2dd493f6e",{ "_id": "a53ae3bc-654c-4d9d-a6aa-62e2dd493f6e", "_type": "dynform", "data": [ { "order": 0, "question": "26da0986-0ec6-4701-842b-57bb26651689" }, { "order": 2, "question": "36bc589a-b162-4c31-809d-2e0ad907480d" }, { "child": [ { "order": 0, "question": "26da0986-0ec6-4701-842b-57bb26651754" }, { "order": 1, "question": "26da0986-0ec6-4701-842b-57bb26647854" } ], "order": 1, "question": "9f76b48f-962b-4f6f-b582-ed3955576b9c" }, { "order": 3, "question": "dd59dfa3-ec2e-4586-9984-b3143c279c2b" } ] });
UPSERT INTO default VALUES("26da0986-0ec6-4701-842b-57bb26647854", { "_id": "26da0986-0ec6-4701-842b-57bb26647854", "_type": "question", "childhidekey": "", "childhidevalue": "", "children": [], "class": "", "controlType": "TextboxQuestion", "function": "", "key": "condition2", "label": "Conditional Q 2", "options": [], "order": 0, "placeholder": "Please provide Condition 2 Answer", "required": true, "type": "TextboxQuestion", "value": "" });
UPSERT INTO default VALUES("26da0986-0ec6-4701-842b-57bb26651689",{ "_id": "26da0986-0ec6-4701-842b-57bb26651689", "_type": "question", "childhidekey": "", "childhidevalue": "", "children": [], "class": "", "controlType": "TextboxQuestion", "function": "", "key": "phoneNumber", "label": "Phone Number", "options": [], "order": 0, "placeholder": "Please provide Phone Number", "required": true, "type": "TextboxQuestion", "value": "" });
UPSERT INTO default VALUES("26da0986-0ec6-4701-842b-57bb26651754",{ "_id": "26da0986-0ec6-4701-842b-57bb26651754", "_type": "question", "childhidekey": "", "childhidevalue": "", "children": [], "class": "", "controlType": "TextboxQuestion", "function": "", "key": "condition1", "label": "Conditional Q 1", "options": [], "order": 0, "placeholder": "Please provide Conditional Question", "required": true, "type": "TextboxQuestion", "value": "" });
UPSERT INTO default VALUES("36bc589a-b162-4c31-809d-2e0ad907480d",{ "_id": "36bc589a-b162-4c31-809d-2e0ad907480d", "_type": "question", "childhidekey": "", "childhidevalue": "", "children": [], "class": "", "controlType": "TextboxQuestion", "function": "", "key": "lastName", "label": "Last Name", "options": [], "order": 0, "placeholder": "Please provide Last Name", "required": true, "type": "TextboxQuestion", "value": "" });
UPSERT INTO default VALUES("9f76b48f-962b-4f6f-b582-ed3955576b9c",{ "_id": "9f76b48f-962b-4f6f-b582-ed3955576b9c", "_type": "question", "childhidekey": "", "childhidevalue": "", "children": [], "class": "", "controlType": "TextboxQuestion", "function": "", "key": "emailAddress", "label": "E-Mail Address", "options": [], "order": 0, "placeholder": "Please provide Email Address", "required": true, "type": "TextboxQuestion", "value": "" });
UPSERT INTO default VALUES("dd59dfa3-ec2e-4586-9984-b3143c279c2b",{ "_id": "dd59dfa3-ec2e-4586-9984-b3143c279c2b", "_type": "question", "childhidekey": "", "childhidevalue": "", "children": [], "class": "", "controlType": "TextboxQuestion", "function": "", "key": "firstName", "label": "First Name", "options": [], "order": 0, "placeholder": "Please provide First Name", "required": true, "type": "TextboxQuestion", "value": "" });
SELECT
(SELECT RAW q
FROM default AS q
WHERE q._type = "question" AND q._id = d.question)[0] AS question,
CASE WHEN ARRAY_LENGTH(childqs) > 0
THEN (SELECT RAW q FROM default AS q WHERE q._type = "question" AND q._id IN childqs)
ELSE MISSING
END AS children,
d.`order`
FROM default AS c
UNNEST c.data AS d
LET childqs = (ARRAY v.question FOR v WITHIN d.child WHEN v.question IS NOT MISSING END)
WHERE c._type = "dynform"
ORDER BY d.`order` ;