我想使用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}
哪种有点类似于我想要的,但不完全相同。有没有一种方法可以将其合并或合并,以使属性组合在一起?
在Neo4j 3.1+中,您还可以使用地图投影(àGraphQL)
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
https://neo4j.com/blog/cypher-graphql-neo4j-3-1-preview/