Unique Genres

Using WITH for map projection to limit results

Using the query you just wrote, answer this question:

Genres?

With the previous query:

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)

How many unique genres are represented in these top four movies?

  • ✓ 4

Hint

Look at the result returned and make a note of the names of the Genres for each movie.

How many unique Genre names occur in these top 4 movies?

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)

How many unique Genre names occur in these top 4 movies?

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

Summary

In this challenge, you answered another question about the graph.

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