Path表示return一个唯一的节点和没有关系
Path that return a unique node and no relationship
我有这个密码查询:
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格式(节点和链接)。
我有这些案例:
起始节点不是应用程序-->路径return所有节点和关系所以响应良好
起始节点已经是一个应用程序,所以路径return这个节点然后我有这个响应:
{“节点”:[],“链接”:[]}
通常我会有:
{"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), name: n.name, labels: labels(n)}) as nl
RETURN {nodes: nl}
我的反应很好:
{"nodes":[{"name":"nodeName","id":111,"labels":["application"]}]}
所以问题出在具有关系的 collect() 中,因为它是空的,我不知道该如何解决?
谢谢。
我找到了解决方案,问题是路径 return 是一个唯一的节点,因此关系将是一个空列表,当您展开一个空列表时,它会清除行
如果你想在这里找到讨论:https://community.neo4j.com/t/path-that-return-a-unique-node-and-no-relationship/34719/2
我有这个密码查询:
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格式(节点和链接)。 我有这些案例:
起始节点不是应用程序-->路径return所有节点和关系所以响应良好
起始节点已经是一个应用程序,所以路径return这个节点然后我有这个响应:
{“节点”:[],“链接”:[]}
通常我会有:
{"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), name: n.name, labels: labels(n)}) as nl
RETURN {nodes: nl}
我的反应很好:
{"nodes":[{"name":"nodeName","id":111,"labels":["application"]}]}
所以问题出在具有关系的 collect() 中,因为它是空的,我不知道该如何解决? 谢谢。
我找到了解决方案,问题是路径 return 是一个唯一的节点,因此关系将是一个空列表,当您展开一个空列表时,它会清除行 如果你想在这里找到讨论:https://community.neo4j.com/t/path-that-return-a-unique-node-and-no-relationship/34719/2