Adding the Director Label

In a previous Challenge, you added the Actor label to the nodes in the graph.

Modify the query to add a DIRECTOR label the Person nodes that have the outgoing DIRECTED relationship.

cypher
MATCH (p:Person) 
WHERE exists ((p)-[:ACTED_IN]->()) 
SET p:Actor

Your code should add 2 labels to the graph.

After refactoring the graph, you must test any use cases that are affected.

Use case #2: What person directed a movie?

Modify this query to use the Director label, then test this use case using the movie, Hoffa.

cypher
MATCH (p:Person)-[:DIRECTED]-(m:Movie)
WHERE m.title = 'Hoffa'
RETURN  p.name AS Director

It should return Danny DeVito.

Validate Results

Once you have add the DIRECTOR labels, click the Check Database button and we will check the database for you.

Hint

All nodes that have the DIRECTED outgoing relationship will need to have an additional Director label.

Solution

This query will add the Director label to all Person nodes connected to a Movie by at least one DIRECTED relationship.

cypher
MATCH (p:Person)
WHERE exists ((p)-[:DIRECTED]->())
SET p:Director

Summary

In this challenge, you demonstrated that you can refactor the graph to add a DIRECTOR label to some of its nodes and retest relevant use cases.

Your instance model should now look like this:

Instance Model thus far

In the next lesson, you will learn some tips about what not to do with labels in your graph data model.