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.

Cypher query with unlimited depth and condition on relationship

myshareit
Node Clone

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!

1 ACCEPTED SOLUTION

Hello @myshareit

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

Regards,
Cobra

View solution in original post

2 REPLIES 2

Hello @myshareit

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

Regards,
Cobra

myshareit
Node Clone

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