Adding Genres

Add relationships to a map projection

This query also returns the actors in the top 10 movies by IMDb rating.

cypher
MATCH (n:Movie)
WHERE n.imdbRating IS NOT NULL
WITH n {
  .title,
  .imdbRating,
  actors: [ (n)<-[:ACTED_IN]-(p) | p { .imdbId, .name } ]
}
ORDER BY n.imdbRating DESC
LIMIT 10
RETURN collect(n)

The ACTED_IN relationship is used to created a list of actors for each movie. The properties imdbId and name are returned for each actor.

Modify this query to add the genres to the map projection. You will need to use the IN_GENRE relationship and return the name property for each genre.

Click to reveal the solution
cypher
MATCH (n:Movie)
WHERE n.imdbRating IS NOT NULL
WITH n {
  .title,
  .imdbRating,
  actors: [ (n)<-[:ACTED_IN]-(p) | p { .imdbId, .name } ],
  genres: [ (n)-[:IN_GENRE]->(g) | g {.name} ]
}
ORDER BY n.imdbRating DESC
LIMIT 10
RETURN collect(n)

Click Complete when you are ready to move on.

Summary

In this challenge, you added relationships to the map projection using WITH.

In the next lesson, you will learn about using WITH to pipeline queries with multiple steps.