繁体   English   中英

Py2neo与Neo4j的关系

[英]Relation in Py2neo with Neo4j

我如何获得关系的结束节点。 例如:

rels = graph_db.match(start_node=user, rel_type="is_post_owner")

因此,我如何获得起始节点用户的所有末端节点。

问候,塞缪尔

像这样:

rels = graph_db.match(start_node=user, rel_type="is_post_owner")
end_nodes = [rel.end_node for rel in rels]

match方法返回的每个关系都是标准的Relationship对象,可以这样使用。

你可以使用密码

START a=node(id) //replace with the id of the node you want to start 
MATCH p=a-[:is_post_owner*..]->x //get all the paths to all nodes with rel:is_post_owner
WHERE NOT(x-->()) //exclude nodes with Direction Out Relationships "end nodes"
RETURN x //get the end nodes

这样,返回的节点将成为图的叶节点,而与方向无关。

正如Thomas所说的那样,他绝对正确,您应该在where子句中包括关系类型,这样您就只能获得该关系的结束节点,而返回的节点可以具有其他具有方向输出的关系(不是叶节点),它们是所请求关系的末端节点

 START a=node(id) 
 MATCH p=a-[r:is_post_owner*..]->x 
 WHERE NOT(x-->(r)) 
 RETURN x 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM