1 Node - It is question node which has question Id and question Text as property
2 Node - It has questionId as property and keys are questions answers
So now I want to get return the question Text and their answers in one object.
I have written the following query:
MATCH(a:Answers) with keys(a) as questionIds,a
UNWIND questionIds as questionId
MATCH(q:Question{questionId:questionId})
RETURN collect({question:q.questionText,answer:a.questionId}) as questionanswers
Now how to return the answers as a.questionId is not allowed as questionId is not the property name it is the variable.
MATCH (a:Answers) WITH a, keys(a) AS questionIds
UNWIND questionIds AS questionId
MATCH (q:Question{questionId:questionId})
RETURN collect({question:q.questionText, answer:a[questionId]}) AS questionanswers