Cypher query with unlimited depth and condition on relationship

I have the following Cypher query which works fine:

MATCH (c:Company)-[r:CONTAINS]->(e) WHERE r.associationType='COMPOSITION' return c, e

Now, I'd like to go down to the unlimited depth with [r:CONTAINS] relationship and return all of the nodes, something like this:

MATCH (c:Company)-[r:CONTAINS*]->(e) WHERE r.associationType='COMPOSITION' return c, e

I added * there, but right now the query fails with the following error:

Type mismatch: expected Map, Node, Relationship, Point, Duration, Date, Time, LocalTime, LocalDateTime or DateTime but was List (line 1, column 44 (offset: 43))
"MATCH (c:Company)-[r:CONTAINS*]->(e) WHERE r.associationType='COMPOSITION' return c, e"

What am I doing wrong and how to properly implement such query? Thanks!

Hello @myshareit :slight_smile:

MATCH p=(:Company)-[:CONTAINS*]->()
WHERE all(r IN relationships(p) WHERE r.associationType = 'COMPOSITION')
RETURN nodes(p) AS nodes

Regards,
Cobra

1 Like

Hello @Cobra thank you very much ! This is exactly what I need!

1 Like