Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
08-13-2020 04:57 AM
Hello
I have two nodes with the following details:
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.
Thanks
Solved! Go to Solution.
08-13-2020 06:02 AM
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
08-13-2020 05:24 AM
08-13-2020 05:29 AM
Question Node - {questionId: "xfElaSuQ", questionText: "What are you doing?"}
AnswerNode - {xfElaSuQ: "This is the answer for the question"}
Return Node: {question: "What are you doing?", answer: "This is the answer for the question"}
08-13-2020 05:31 AM
Your first query is not solving the problem?
08-13-2020 05:34 AM
It is giving an error because "a.questionId" in this questionId is variable from the unwind function such property does not exist in the node
08-13-2020 05:37 AM
There is no relation in your model?
08-13-2020 05:39 AM
Yes there are relationships but all that are not related to the output which I required
08-13-2020 06:02 AM
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
All the sessions of the conference are now available online