user3703910
user3703910

Reputation: 644

cypher neo4j iterate over graph starting with node and ending with node

I have a graph at neo4j that looks like this : (1)->(2)->(3)->(4)->(5)->(6) I want to start iterating start from the third node to the fifth node and get them how can I do this ?

Upvotes: 0

Views: 149

Answers (1)

Dave Bennett
Dave Bennett

Reputation: 11216

This one can probably answered many ways but here is one example.

Consider this test data...

create (t1:Test {name:'1'})
create (t2:Test {name:'2'})
create (t3:Test {name:'3'})
create (t4:Test {name:'4'})
create (t5:Test {name:'5'})
create (t6:Test {name:'6'})
create t1-[:JOINED_TO]->t2
create t2-[:JOINED_TO]->t3
create t3-[:JOINED_TO]->t4
create t4-[:JOINED_TO]->t5
create t5-[:JOINED_TO]->t6

Then you can return the 3rd to 5th nodes with the following query...

match p=(:Test {name:'3'})-[:JOINED_TO*]->(:Test {name:'5'})
return p

Upvotes: 1

Related Questions