We want to add some relationships between User nodes and Movie nodes so we can test our model.
In this challenge, you will create RATED relationships that include the rating property.
This Cypher creates one relationship between Sandy Jones and Apollo 13 with a rating of 5.
MATCH (sandy:User {name: 'Sandy Jones'})
MATCH (clinton:User {name: 'Clinton Spencer'})
MATCH (apollo:Movie {title: 'Apollo 13'})
MATCH (sleep:Movie {title: 'Sleepless in Seattle'})
MATCH (hoffa:Movie {title: 'Hoffa'})
MERGE (sandy)-[:RATED {rating:5}]->(apollo)
Add additional MERGE
clauses to create the remaining 4 relationships as per the table below:
Note: The first relationship is already created for you.
User.name | Relationship | rating | Movie.title |
---|---|---|---|
'Sandy Jones' |
RATED |
5 |
'Apollo 13' |
'Sandy Jones' |
RATED |
4 |
'Sleepless in Seattle' |
'Clinton Spencer' |
RATED |
3 |
'Apollo 13' |
'Clinton Spencer' |
RATED |
3 |
'Sleepless in Seattle' |
'Clinton Spencer' |
RATED |
3 |
'Hoffa' |
Use MATCH
to find the User and Movie nodes, then use MERGE
to create the relationships between the two nodes.
Remember that you must specify or infer(left-to-right) a direction when you create a relationship.
You should create a total of 5 RATED relationships in the graph, each with a property, rating.
Validate Results
Once you have run the query, click the Check Database button and we will check the database for you.
Hint
You should add four more MERGE
clauses to the bottom of the statement to create the remaining relationships.
For example, to add the relationship between Sandy Jones and Sleepless in Seattle with a rating of 4, you would add the following MERGE
clause:
MERGE (sandy)-[:RATED {rating:4}]->(sleep)
Solution
Here is the completed Cypher statement with the four additional MERGE
clauses:
MATCH (sandy:User {name: 'Sandy Jones'})
MATCH (clinton:User {name: 'Clinton Spencer'})
MATCH (apollo:Movie {title: 'Apollo 13'})
MATCH (sleep:Movie {title: 'Sleepless in Seattle'})
MATCH (hoffa:Movie {title: 'Hoffa'})
MERGE (sandy)-[:RATED {rating:5}]->(apollo)
MERGE (sandy)-[:RATED {rating:4}]->(sleep)
MERGE (clinton)-[:RATED {rating:3}]->(apollo)
MERGE (clinton)-[:RATED {rating:3}]->(sleep)
MERGE (clinton)-[:RATED {rating:3}]->(hoffa)
Summary
In this challenge, you demonstrated that you can create some relationships to support your instance model.
Your instance model should now look like this:

In the next module, you will learn why and how to refactor your data model.