Get the nodes which are all connected with my input node using py2neo and flask

Viewed 519
1 Answers

Suppose your nodes have a property called nodeid, you can use NodeMatcher() to match node 2 (see Node Matching), then iterate over its adjacent nodes:

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,)))

Otherwise, just run a cypher query:

q = '''MATCH (a)-[r]-(b) where a.nodeid='2' RETURN b'''
[i for i in graph.run(q)]
Related