Testing List Inclusion

Neo4j supports storing a single value or an array of values of the same type within a property.

In our data model, :Movie nodes have a countries property which contains an array of strings. For example ['UK', 'Germany', 'Italy'].

Finding Jamaican Movies

Find movies from "Jamaica".

Update the WHERE clause to test if a Movie node has a countries property that includes "Jamaica".

cypher
MATCH (m:Movie) 
WHERE ??????
RETURN m.title, m.countries 

Which of the following movies was produced in Jamaica?

  • ❏ "Before Sunrise"

  • ❏ "Blue Sky"

  • ✓ "Harder They Come, The"

  • ❏ "Walk in the Clouds, A"

Hint

Use IN to test whether "Jamaica" is in the countries list property for the Movie node.

Solution

The answer is "Harder They Come, The".

You can run the following query to see the result:

cypher
MATCH (m:Movie) 
WHERE "Jamaica" IN m.countries
RETURN m.title, m.countries 

Summary

In this challenge, you wrote and executed a basic query to test if a value is in a list for a node.

The next lesson will teach you more about evaluating strings in your queries.