CREATE INDEX ix1 ON default(DISTINCT ARRAY v.question_id FOR v IN questions END)
WHERE type = "questionnaire";
SELECT d, COUNT(META(q).id) AS count
FROM default AS d USE KEYS ["question:100","question:100"]
LEFT JOIN default AS q
ON ANY v IN q.questions SATISFIES v.question_id = META(d).id END AND q.type = "questionnaire"
GROUP BY d;
I managed to construct the below one, but still not perfect…
It returns the data in case there is a questionnaire document but if there isn’t one, none is being returned…
SELECT q.question_id, count(q.question_id) cnt FROM default x
UNNEST questions AS q
WHERE x.type = ‘questionnaire’ AND
q.question_id IN [‘question:10013’, …]
GROUP BY q.question_id) as questionnaire
JOIN default question ON KEYS questionnaire.question_id
CREATE INDEX ix1 ON default(ALL ARRAY qid.question_id FOR qid IN questions END)
WHERE type = "questionnaire";
SELECT d, FIRST v.cnt FOR v IN questionnaire WHEN v.qid = META(d).id END cnt
FROM default AS d USE KEYS ["question:100","question:100"]
LET questionnaire = ( SELECT qid.question_id, COUNT (DISTINCT META(q).id) AS cnt
FROM default AS q
UNNEST q.questions AS qid
WHERE qid.question_id IN ["question:100","question:100"] END AND q.type = "questionnaire"
GROUP BY qid.question_id)
;