Creating and Working with Lists

Movies with 1 or 2 Actors

Write and execute a query to return the movies that have one or two actors. You will return the movie title, the year the movie was released and the actors for the movie.

Once you executed, enter the number of movies returned below and click Check Answer.

  • ✓ 139

Hint

Your query should:

  1. Find all movies with actors. (single path using the :ACTED_IN relationship)

  2. Collect the actor names nodes as a list. (Use `WITH)

  3. Test the size of the Actors list to be less than or equal to 2.(Use WHERE)

  4. Return the movie title, movie year and Actors.

How many movies does it return?

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 (m)<-[:ACTED_IN]-(a:Person)
WITH  m, collect(a.name) AS Actors
WHERE size(Actors) <= 2
RETURN m.title AS Movie, m.year as Year, Actors ORDER BY m.year

How many movies does it return?

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

Summary

In this challenge, you wrote and executed a query to answer a question about the graph where you aggregated data.

In the next lesson, you will learn about aggregation with count().