cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Path between Nodes

I want to retrieve nodes based on the hop count.
I'll give the start node and end node and also the hop count
So, give me those nodes who matches the hop in the database

1 REPLY 1

intouch_vivek
Graph Steward

Hi @gaminbot3813

With the below dataset
Merge(a:N{name:'A'})-[:Related_TO]->(b:N{name:'B'})-[:Related_TO]-(c:N{name:'C'})-[:Related_TO]->(d:N{name:'D'})
Merge(a:N{name:'A'})-[:Related_TO]->(b:N{name:'B'})-[:Related_TO]->(d:N{name:'D'})

Query Used
Match p=(a:N{name:$startNode})--(b:N{name:$endNode}) with a as a, nodes(p) as nodesInPath where $hopCount =size(nodesInPath) -2 return a,nodesInPath

:param hopCount=>1
:param startNode=>'A'
:param endNode=>'D'