简体   繁体   中英

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

I want to fetch the connected nodes from ny neo4j database. 在此处输入图像描述

For example If I give the input as 2 and then I have to fetch 1,3,4 and 5.I tried to explore the question but answer is related to neo4j only. I need a query with py2neo. is there anyway i can get it?

I tried this How to get all nodes connected to one node in neo4j graph in py2neo How to get all connected nodes in neo4j graph in py2neo

But these are all with neo4j not with py2neo

Suppose your nodes have a property called nodeid , you can useNodeMatcher() 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)]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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