1

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.

Manohar CS
  • 31
  • 8

1 Answers1

3
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 ...
...
Nicole White
  • 7,720
  • 29
  • 31
  • Thanks for your suggestion. As mentioned how to capture this matching value in variable and pass further down to query. Lets say depending on this matching value I want to do something. – Manohar CS Jun 13 '16 at 14:00
  • I've edited my answer to show how you'd carry the value over. – Nicole White Jun 13 '16 at 14:05
  • If you want the value to be a list don't use UNWIND. UNWIND expands the list into rows. – Nicole White Jun 13 '16 at 14:06
  • Thanks, this works. My complete use case is something like this I have list of Nodes and wanted to establish relationship between nodes depending on certain conditions. Every node has property1 which is array, and property2 which is also array , now to establish relation among these 2 nodes they should have property1 containing one common element, and then one matching element from property2 – Manohar CS Jun 13 '16 at 14:13