user2090310
user2090310

Reputation: 13

how to find all paths with a given node

I have a graph like this:

here is th graph

I want to find all paths with a given node. For example, If node "fcproc" is given, I expect to get a path("itest->bkqa->fcproc"); If node "itest" is given, I expect to get 2 paths("itest->bkqa->fcproc", "itest->xmonitor").

How to write the cypher?

Upvotes: 1

Views: 2092

Answers (1)

cybersam
cybersam

Reputation: 67044

Assuming that your target node has the label Foo and the name property value "fcproc", something like this should work:

MATCH p=(root)-[*0..]->(:Foo {name: "fcproc"})-[*0..]->(leaf)
WHERE NOT ()-->(root) AND NOT (leaf)-->()
RETURN p;

The variable-length relationship pattern [*0..] matches relationship lengths of 0 or more (where 0 means there is actually no relationship and the 2 "endpoints" are the same node). This allows the target node to be the same as the root or leaf node.

Upvotes: 4

Related Questions