Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to match all paths between two nodes with a relationship property filter?

Tags:

neo4j

cypher

I am trying to perform a query to retrieve all paths between two nodes a and b in which all the paths there is a relationship property fulfilled.

I have tried in many ways but I am not able to success.

MATCH p=(o{value:"a"})-[r*]-(x{value:"b"}) 
WHERE has(r.property) AND r.property="foo" 
RETURN p

I have changed the relationship part to [r*..] and many other options but not working.

The function shortestpath does not help me because I want not only the shortest but all the possibilities.

Can someone help me or tell me which is the error in the query?

like image 725
ddomingo Avatar asked Oct 31 '25 22:10

ddomingo


1 Answers

What you're looking for is the ALL predicate on the relationships collection of the path :

MATCH p=(o{value:"a"})-[r*]-(x{value:"b"})
WHERE ALL(x IN rels(p) WHERE x.property = "foo")
RETURN p

And please use labels !

like image 77
Christophe Willemsen Avatar answered Nov 02 '25 18:11

Christophe Willemsen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!