Nicholas
Nicholas

Reputation: 7501

Return all matching relationships in cypher

I want to retrieve a set of nodes who share an common node in between using difference relationships that can have matching properties. The query I think will look something like this:

start 
    n1=node(8) 
match 
    n1-[r1:HAS_VALUE]->value<-[r2:REQUIRES_VALUE]-object 
where 
    all(x in relationship(r1) 
        where all(y in relationship(r2) where x.name==y.name)) 
return 
    object

but cypher returns SyntaxException: unknown function when I run this. Is there any way this type of query can be done?

Upvotes: 0

Views: 1513

Answers (1)

Andres
Andres

Reputation: 1454

I would write this query like this:

start 
    n1=node(8) 
match 
    n1-[r1]->value<-[r2]-object 
where 
    r1.name = r2.name
return 
    object

The ALL function is used when you have a variable length relationship - in this query r1 and r2 hold a single relationship, and not a collection of them.

HTH,

Andrés

Upvotes: 1

Related Questions