Tom Hanks Movies in 1995

Tom Hanks Movies in 1995

Write a query to return the paths to other actors from Tom Hanks where the movie was released in 1995.

How many paths are returned?

Once you execute the query, enter the number of paths returned below and click Check Answer.

  • ✓ 6

Hint

Start with this MATCH clause to retrieve all paths from Tom Hanks:

MATCH p = (a:Actor)-[:ACTED_IN*2]-(a2:Actor)
WHERE
a.name = 'Tom Hanks'

Then test if any of the nodes in the paths have a year property with a value of 1995.

Return the paths.

How many paths are returned?

Once you have entered the answer, click the Try Again button below to continue.

Solution

You can run the following query to find the answer:

cypher
MATCH p = (a:Actor)-[:ACTED_IN*2]-(a2:Actor)
WHERE
a.name = 'Tom Hanks'
AND any(x IN nodes(p) WHERE x.year = 1995)
RETURN p

How many paths are returned?

Once you have entered the answer, click the Try Again button below to continue.

Summary

In this challenge, you wrote a query that uses a predicate function to determine if the elements of a list meet a criteria,.

In the next lesson, you will learn about Cypher list comprehension.