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 ?

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!

2 Likes

Thank you, Luise !

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

1 Like