kkulkarn
kkulkarn

Reputation: 345

Neo4j: Relationship direction cypher

For the cypher -

match (m)-[r]-(n) where m.name = 'XYZ' return n.name, type(r), m.name

n.name      type(r)         m.name
XYZ         belongs_to      Ordering Status
XYZ         runs_on_queue   inbound
XYZ         runs_on_db      DBxc

In this case, Ordering Status is a business service that "owns" XYZ & the relation is defined as follows:

CREATE (XYZ)-[:belongs_to]->(Order)

Type(r) only gives the relation but not the direction of the relation. Is this still the optimal way to get the direction - I also noticed a comment on not being available for Cypher

Neo4j Cypher Get Relationship Direction

Thanks.

Upvotes: 1

Views: 881

Answers (1)

Nicole White
Nicole White

Reputation: 7790

Not as a function, but you can do this:

MATCH (m)-[r]-(n)
RETURN m.name, TYPE(r), n.name,
       CASE WHEN STARTNODE(r) = m THEN 'outgoing' ELSE 'incoming' END AS direction

Upvotes: 8

Related Questions