Challenge: Cypher Projection

Now for a challenge.

Create a Cypher Projection

Create a cypher projection representing all User nodes that have rated a Movie with a release year greater than 2014.

The projection must use the name movie-ratings-after-2014

Complete the following Cypher query by replacing the ?????? with the correct values.

cypher
MATCH (??????:User)-[r:RATED]->(??????:Movie)
WHERE ??????.year > ????
WITH gds.graph.project(
  '??????',
  ??????,
  ??????
) AS g
RETURN
  g.graphName AS graph, g.nodeCount AS nodes, g.relationshipCount AS rels

Once you have created the projection, you can verify that it was created successfully by listing the graph projections in the database:

cypher
CALL gds.graph.list() YIELD graphName

Click the Check Database button to verify that there is a projection named movie-ratings-after-2014 and that the task is complete.

Hint

The Cypher needed to create the projection is:

cypher
MATCH (source:User)-[r:RATED]->(target:Movie)
WHERE target.year > 2014

The source and target nodes should be passed to the gds.graph.project function:

cypher
MATCH (source:User)-[r:RATED]->(target:Movie)
WHERE target.year > 2014

WITH gds.graph.project(
  '??????',
  ??????,
  ??????
) AS g
RETURN
  g.graphName AS graph, g.nodeCount AS nodes, g.relationshipCount AS rels

Solution

Here is the correct query to create the Cypher projection.

cypher
MATCH (source:User)-[r:RATED]->(target:Movie)
WHERE target.year > 2014
WITH gds.graph.project(
  'movie-ratings-after-2014', 
  source, 
  target
) AS g
RETURN
  g.graphName AS graph, g.nodeCount AS nodes, g.relationshipCount AS rels

Lesson Summary

In this lesson we learned about Cypher projections. What they are, how and when to use them.