使用 py2neo 和 flask 获取所有与我的输入节点连接的节点
Get the nodes which are all connected with my input node using py2neo and flask
我想从 ny neo4j 数据库中获取连接的节点。
例如,如果我将输入设为 2,然后我必须获取 1、3、4,并且 5.I 试图探索该问题,但答案仅与 neo4j 相关。我需要使用 py2neo 进行查询。无论如何我可以得到它吗?
我试过了
How to get all nodes connected to one node in neo4j graph in py2neo
但是这些都是用neo4j而不是py2neo
假设您的节点有一个名为 nodeid
的 属性,您可以使用 NodeMatcher()
to match node 2
(see Node Matching),然后遍历其相邻节点:
from py2neo import Graph, NodeMatcher
matcher = NodeMatcher(graph)
node = matcher.match(nodeid="2").first()
list(r.end_node["nodeid"] for r in graph.match(nodes=(node,)))
否则,只需运行一个密码查询:
q = '''MATCH (a)-[r]-(b) where a.nodeid='2' RETURN b'''
[i for i in graph.run(q)]
我想从 ny neo4j 数据库中获取连接的节点。
例如,如果我将输入设为 2,然后我必须获取 1、3、4,并且 5.I 试图探索该问题,但答案仅与 neo4j 相关。我需要使用 py2neo 进行查询。无论如何我可以得到它吗?
我试过了
How to get all nodes connected to one node in neo4j graph in py2neo
但是这些都是用neo4j而不是py2neo
假设您的节点有一个名为 nodeid
的 属性,您可以使用 NodeMatcher()
to match node 2
(see Node Matching),然后遍历其相邻节点:
from py2neo import Graph, NodeMatcher
matcher = NodeMatcher(graph)
node = matcher.match(nodeid="2").first()
list(r.end_node["nodeid"] for r in graph.match(nodes=(node,)))
否则,只需运行一个密码查询:
q = '''MATCH (a)-[r]-(b) where a.nodeid='2' RETURN b'''
[i for i in graph.run(q)]