我想使用cypher返回一些形式:
{
name: 'Name of Parent Node',
property1 : 'some property of parent node',
property2 : 'some other property'
children: [...some array of children...]
}
到目前为止,我已经完成了以下工作:
MATCH (p:Parent)-[:SOME_RELATIONSHIP]->(c:Child)
WITH collect(c) as children, p
RETURN {properties: properties(p), children: children}
哪种类似于我想要的但不完全相同。有没有办法合并或组合它,以便我一起得到属性?
答案 0 :(得分:4)
在Neo4j 3.1+中,您还可以使用地图投影(àrarGraphQL)
MATCH (p:Parent)-[:SOME_RELATIONSHIP]->(c:Child)
RETURN p {.property1, .property2, children: collect(c)} AS info
您还可以从子节点中仅选择几个属性:
MATCH (p:Parent)-[:SOME_RELATIONSHIP]->(c:Child)
RETURN p {.property1, .property2,
children: collect(c {.cprop1, .cprop2})
} AS info
答案 1 :(得分:0)
如果始终从父节点返回相同的属性
MATCH (p:Parent)-[:SOME_RELATIONSHIP]->(c:Children)
WITH collect(c) as children,p
return p.name as name,p.firstproperty,p.secondproperty,children