简体   繁体   中英

How to get the direction of relationship in Neo4J?

I need to find out all the related nodes from a given node. I also need to identify the direction, whether it is incoming or outgoing, plus the ID, labels on each related node. Following is the query I am trying out. Would it be effective query? Is there any other simpler way?

MATCH (o)<-[or]-(e)<-[ir]-(i) 
WHERE e.firstName='Sid' 
RETURN o,ID(o),TYPE(or),or,e,ID(e),TYPE(ir),ir,i,ID(i)

With above query I am able to identify o as outgoing node and i as incoming node.

  1. Use Labels + Indexes to find your node
  2. You already specify the direction in your pattern so you know between your nodes
  3. in case you don't you can get the direction regarding a node with:

this statement:

MATCH (n:Foo)-[r]-(m) WHERE n.id = "bar"
RETURN n,m,type(r), (startNode(r) = n) as out_n

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM