DIRECTED relationship

To complete this challenge, you will need to create the DIRECTED relationships between the Person and Movie nodes.

DIRECTED relationships

Your challenge is to write a Cypher statement to create the DIRECTED relationship between the Person and Movie nodes.

The directed.csv file contains just the movieId and person_tmdbId IDs.

Unlike the ACTED_IN relationship, the DIRECTED relationship has no properties (e.g. role), so you will not need to use the SET clause.

ACTED_IN relationship

Here is the Cypher you used to create to the ACTED_IN relationship.

cypher
LOAD CSV WITH HEADERS
FROM 'https://data.neo4j.com/importing-cypher/acted_in.csv' AS row
MATCH (p:Person {tmdbId: toInteger(row.person_tmdbId)})
MATCH (m:Movie {movieId: toInteger(row.movieId)})
MERGE (p)-[r:ACTED_IN]->(m)
SET r.role = row.role

To verify that you created the DIRECTED relationship successfully, run the following Cypher statement:

cypher
MATCH (p:Person)-[r:DIRECTED]->(m:Movie) RETURN p, r, m LIMIT 25

Directed and acted in

Once you have created the ACTED_IN and DIRECTED relationships, you can use the data to find people who directed and acted in the same movie.

cypher
MATCH (p:Person)-[:ACTED_IN]->(m:Movie)<-[:DIRECTED]-(p:Person)
RETURN p, m

Validate relationships

Once you have created DIRECTED relationships, click the Check Database button to verify that the task is complete.

Hint

Create and run a Cypher statement for the DIRECTED relationships, which:

  • Uses the directed.csv file

  • Uses MERGE to create the directed relationship.

Solution

Run this Cypher statement to create the DIRECTED relationships:

cypher
LOAD CSV WITH HEADERS
FROM 'https://data.neo4j.com/importing-cypher/directed.csv' AS row
MATCH (p:Person {tmdbId: toInteger(row.person_tmdbId)})
MATCH (m:Movie {movieId: toInteger(row.movieId)})
MERGE (p)-[r:DIRECTED]->(m)

Summary

In this lesson, you created the Cypher to create the DIRECTED relationship between the Person and Movie nodes.

In the next lesson, you will complete a quiz on the lessons from this module.

Chatbot

Hi, I am an Educational Learning Assistant for Intelligent Network Exploration. You can call me E.L.A.I.N.E.

How can I help you today?