1

So in Neo4j if you have various nodes and they have a property with 1 value as follows:

n.stringProp = "something"

Then you can get various nodes that comply with any property within a query list using a MATCH query like

MATCH (n) 
WHERE n.stringProp IN ["something", "somethingElse", "etc"]
RETURN n

However if you have nodes with properties that are lists, as follows:

n.stringListProp = ["red", "purple", "green"]

And you want to get nodes that have any 1 or more of the tags in a query list in their list properties then you cannot simply do a query like:

MATCH (n)
WHERE n.stringListProp IN ["red"]
RETURN n

And you also cannot use CONTAINS because that is for substrings. So you cannot do:

MATCH (n)
WHERE n.stringListProp CONTAINS "red"
RETURN n

And you can't loop through them using a FOREACH because FOREACH is only for CREATE, MERGE or DELETE operations. So I think you have to use UNWIND for this type of MATCH query but I'm really not sure how to structure this query.

If anyone knows how to do this can you please help me out?

2

1 Answer 1

7

As per the comments on my Question, the ANY predicate function solves this problem.

See MATCH query below:

MATCH (n)
WHERE ANY (color IN n.stringListProp WHERE color IN ["red", "pink", "cyan"])
RETURN n

This query will check if any of the nodes with a stringListProp property has any of the items in the query list.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.