i have a tree structure (project)-[:IS_PARENT_OF]->(projectChild)
A project can have multiple children, what i would like to do is a query that creates a virtual node that contains all the children of a parent.
So the node would have data like this :
parent: "project 1",
children:['cohort', 'protocol', etc...]
I tried this query
MATCH (p:Project)-[:IS_PARENT_OF]->(c)
CALL apoc.create.vNode(['Project'], {name: p.name, children: [c.name]}) YIELD node
RETURN node
But i only get one child:
{
"identity": -32,
"labels": [
"Project"
],
"properties": {
"name": "project 1",
"children": [
"Experimental design"
]
}
}
Does someone know how to get multiple children in my vNode ?
>Solution :
Since you seem to have tried a form of pattern comprehension, this is probably what you need:
MATCH (p:Project)
CALL apoc.create.vNode(
['Project'],
{
name: p.name,
children: [(p)-[:IS_PARENT_OF]->(c) | c.name]
}
) YIELD node
RETURN node
which would return an empty array [] in case the project does not have children.
