Manohar CS
Manohar CS

Reputation: 31

Neo4J - find if value in array property of 2 nodes matches

Hi I have a use case where I have a node with property which is array.

*

Node({name:'a', colors:['red','green','blue']})
Node({node:'b',colors:['blue','black','red']})

*

Now I want to find out what is matching value between 2 nodes among their colors property.I shoud be able to get the matching value so as to pass it on further in the query for processing.

Upvotes: 1

Views: 1076

Answers (1)

Nicole White
Nicole White

Reputation: 7790

MATCH (a:Node {name:'a'})
MATCH (b:Node {name:'b'})
RETURN filter(x IN a.colors WHERE x IN b.colors);

If you want to continue with the query:

MATCH (a:Node {name:'a'})
MATCH (b:Node {name:'b'})
WITH filter(x IN a.colors WHERE x IN b.colors) AS v
UNWIND v AS matchingVals
MATCH ...
...

Upvotes: 3

Related Questions