Question

If I have a list of strings. E.g. ["test1","test2","test3","test4"] and have a Neo4j database that contains two nodes with a property myProperty respectively set to "test1" and "test3".

I would like to create a Cypher expression that uses the list and identifies which of the elements in the list isn't present on a node.myProperty - so that it in the above example would return ["test2","test4"]. Is that at all possible - if so how would the cypher expression look?

As an alternative it would be ok to return a list of properties that actually exist - ["test1","test3"]

I could do a statement for each of the list elements, but as the list can get very long, I would like to make it happen in one statement.

Was it helpful?

Solution 2

Sumeet set me in the right direction (+1 for that). However it returns all n.myProperty in my database that is not in the collection. I wanted to return all words in my collection not in any n.myProperty. This is done like this:

MATCH (n:Node) where has(n.myProperty) 
WITH collect(n.myProperty) as set1
return FILTER(t in ["test1","test2","test3","test4"] WHERE NOT t in set1 ) as set2

OTHER TIPS

MATCH (n) where has(n.myProperty) 
WITH collect(n.myProperty) as set1
return FILTER(t in set1 WHERE NOT t in ["test1","test2","test3","test4"]) as set2

The set2 returned will be all those which dont exist as myProperty in the graph

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top