Showing results for 
Search instead for 
Did you mean: 

Cypher for a 'Stopping Point' in a path query?


Hello everyone,

I am new to Cypher and Neo4j. I've been attempting to create a query that will return all Paths up to a 'Stopping Point' at any length. The stopping point being triggered by a node property. Where the hitch comes in is that if the 'stopping point' is not found.... I would like for the full path to be returned. If the stopping point is found, it must exclude the stopping point node from the results.

Currently, I am able to do this by querying up to the stopping point and then reducing the final node out. Then I query again for all paths that do not contain the stopping point. This is very inefficient. Is there a better way? Current example query that I am running:

MATCH path=(:BaseNode { id: 'some_unique_id' })-[*0..]->(other:BaseNode {stoppingProperty: true})
WITH (relationships(path) +
  REDUCE(s=[], y IN nodes(pTop) | CASE WHEN y.stoppingProperty = true THEN s ELSE s + y END)
) as allData

MATCH path2=(:BaseNode { id: 'some_unique_id' })-[*0..]->(:BaseNode)
WHERE NONE(n in nodes(path2) WHERE n.stoppingProperty = true) 

WITH (allData + nodes(p) + relationships(p)) as allData