问题描述
MATCH p=(no {name:'nodeName'})<-[:enfant*0..]-(parent:application)
unwind nodes(p) as n unwind relationships(p) as r
with collect( distinct {id: id(n),name: n.name,labels: labels(n)}) as nl,collect( distinct {source: id(startnode(r)),target: id(endnode(r))}) as rl
RETURN {nodes: nl,links: rl}
这个请求重新运行一个节点与其所有父节点之间的路径,然后转换为d3js格式(nodes&links)。 我有这些情况:
通常我会有:
{"nodes":[{id: 111,name: 'nodeName',labels:['application']}],"links":[]}
当我在没有这样的关系的情况下进行测试时:
MATCH p=(no {name:'nodeName'})<-[:enfant*0..]-(parent:application)
WITH p
unwind nodes(p) as n
with collect( distinct {id: id(n),labels: labels(n)}) as nl
RETURN {nodes: nl}
我有很好的回应:
{"nodes":[{"name":"nodeName","id":111,"labels":["application"]}]}
所以问题出在有关系的 collect() 中,因为它是空的,我不知道我该如何解决? 谢谢。
解决方法
我找到了解决方案,问题是路径返回一个唯一的节点,因此关系将是一个空列表,当您展开一个空列表时,它会清除行 如果你想在这里找到讨论:https://community.neo4j.com/t/path-that-return-a-unique-node-and-no-relationship/34719/2