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.

Difference between --> and ->

Sorry; I'd have to bet this is asked often .. can't find it ..

From this Url (and many examples)
https://neo4j.com/docs/cypher-refcard/current/
and then the subsection titled, 'Patterns',

Sometimes you use --> and sometimes ->

What is the difference please ?

1 ACCEPTED SOLUTION

Hi @daniel.farrell2626 !! Welcome to Neo4j's community!

When you write (with -->):

MATCH (p:Person {name:'Jim'})-->(b:Person) RETURN b 

You are searching for all the nodes who are related to some other by any possible type of relationship in the database (nodes that have relationships going into them, not necessarily out of them). In this example, we are getting all the Person nodes (all the people) who are related with Jim.


But if you write (with -[ ]->):

MATCH (p:Person {name:'Jim'})-[:FRIENDS_WITH]->(b) RETURN b

You are searching for all the nodes that are related to some other node, but only through the FRIENDS_WITH type of relationship, i.e. all the Person nodes who are friends with Jim. So, you use the -[:REL_TYPE]-> notation to specify which type of relationship you want to traverse, and --> notation to search on every possible type of relationship.

Hope this helps!

View solution in original post

2 REPLIES 2

Hi @daniel.farrell2626 !! Welcome to Neo4j's community!

When you write (with -->):

MATCH (p:Person {name:'Jim'})-->(b:Person) RETURN b 

You are searching for all the nodes who are related to some other by any possible type of relationship in the database (nodes that have relationships going into them, not necessarily out of them). In this example, we are getting all the Person nodes (all the people) who are related with Jim.


But if you write (with -[ ]->):

MATCH (p:Person {name:'Jim'})-[:FRIENDS_WITH]->(b) RETURN b

You are searching for all the nodes that are related to some other node, but only through the FRIENDS_WITH type of relationship, i.e. all the Person nodes who are friends with Jim. So, you use the -[:REL_TYPE]-> notation to specify which type of relationship you want to traverse, and --> notation to search on every possible type of relationship.

Hope this helps!

Thank you, Luise !

..............