Top Movies

Using WITH for map projection to limit results

Here is a query, a version of which you saw in the previous lesson:

cypher
MATCH (n:Movie)
WHERE n.imdbRating IS NOT NULL and n.poster IS NOT NULL
// Add WITH clause to return custom data for each movie
ORDER BY n.imdbRating DESC LIMIT 4
RETURN collect(n)

Modify this query by adding a WITH clause that customizes the data returned for each Movie node to include:

  • title

  • imdbRating

  • List of actor names

  • List of Genre names

Then answer this question:

Which actor?

What actor acted in more than one of these top four movies? (Name is case-sensitive)

  • ✓ Al Pacino

Hint

You will customize what is returned for each movie to include:

  • title

  • imdbRating

  • actors

  • genres

The list of actors will be created with:

[ (n)←[:ACTED_IN]-(p) | p { tmdbId:p.imdbId, .name } ]

The list of genres will be created with:

[ (n)-[:IN_GENRE]→(g) | g {.name}]

What actor is in more than one of these top 4 movies? (case-sensitive)

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 (n:Movie)
WHERE n.imdbRating IS NOT NULL AND n.poster IS NOT NULL
WITH n {
  .title,
  .imdbRating,
  actors: [ (n)<-[:ACTED_IN]-(p) | p { tmdbId:p.imdbId, .name } ],
  genres: [ (n)-[:IN_GENRE]->(g) | g {.name}]
}
ORDER BY n.imdbRating DESC
LIMIT 4
RETURN collect(n)

What actor is in more than one of these top 4 movies? (case-sensitive)

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

Summary

In this challenge, you wrote a query to use a WITH clause to return a subset of data using map projection.

In the next challenge, you will answer another question about the graph.