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

1k Views Asked by At

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.

1

There are 1 best solutions below

4
On BEST ANSWER
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 ...
...