cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Specifying constraints on nodes in recursive length relationship match

peey
Node Clone

My target to match looks like the following:

(:A) -[:R]-> (:B {val: 1})-> [:R]-> (:B {val : 2} )-> [:R]-> (:B {val: 3})-> [:R]-> (:B {val : 4})-> [:R]->(:C)

and I can match it with

MATCH (:A)-[:R *]->(C)

but is there a way I can specify constraints for the intermediate nodes? E.g. I want to specify that the val property for them should match up in a sequence (1, 2. 3, 4, ...)

1 REPLY 1

use path
https://neo4j.com/docs/cypher-manual/current/syntax/patterns/#cypher-pattern-path-variables: "MATCH path=(:A)-[:R *]->(C)"
and then use the nodes in each path with "nodes(path)"
but I won't be that sure that they will be returned in the order in which they are present in the path.
Maybe they are: iterate through the nodes and let us know.