databaseneo4jcypher

In Neo4j, why does MATCH (a)-->(b)-->(c) allows a==c, but (a)-->(b)<--(c) doesn't?


Let's take the example in the following site: https://console.neo4j.org/

After creating an edge with:

match (n{name:"Neo"})-->(t{name:"Trinity"}) create (t)-[:LOVES]->(n)

We get the following graph:

enter image description here

The following query:

match (a)-->(b)-->(c) return a,b,c

Returns a result where a==c: enter image description here

But the next query:

match (a)-->(b)<--(c) return a,b,c

Doesn't. I'd expect it to return every edge, since if a==c, then (a)-->(b)<--(c) is equivalent to "(a)-->(b)". Where do I get it wrong?


Solution

  • When the query (a)-->(b)-->(c) returned (neo)-->(trinity)-->(neo), it matched two separate edges, one being (neo)-->(trinity) and the other being (trinity)-->(neo).

    However, the query (a)-->(b)<--(c) cannot be satisfied by the graph unless you go through the edge (neo)-->(trinity) twice.