Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to verify that some nodes exists in a path using cypher

Tags:

neo4j

cypher

I want to get all paths between two nodes so that at least one node from a list of nodes exists in those paths.

how can I do this using cypher ?

like image 263
Armin Balalaie Avatar asked Oct 15 '25 18:10

Armin Balalaie


1 Answers

Assuming you have provided your list of nodes as a cypher collection, would this do the job?

MATCH path=(start)-[r:*1..100]-(end)
WHERE ANY(node_on_path in NODES(path) 
  WHERE node_on_path IN node_collection)

You may also try using a list of values against which the nodes on the path are checked, something like

MATCH path=(start)-[r:1..100]-(end)
WHERE ANY(node_on_path in NODES(path)
  WHERE node_on_path.some_property IN list_of_acceptable_values)
like image 133
jjaderberg Avatar answered Oct 18 '25 14:10

jjaderberg



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!