Task 1: Adding or Updating a Movie
Suppose we do not know if we have the movie Rocketman in our graph. If it is not in the graph, we want to set the createdAt property with the value of datetime(). The datetime() function returns the current date and time. If it is in the graph, we want to set the matchedAt property with the value of datetime(). In either case, we want to set the updatedAt property with the value of datetime().
Modify the Cypher code to use MERGE processing for the Movie node with the title Rocketman:
If the node already exists (
ON MATCH
SET clause):
Set the matchedAt property for the node referenced by m to datetime().
If the node does not exist (
ON CREATE
SET clause):
Set the createdAt property to datetime().
For either case:
Set the updatedAt property to datetime().
Execute your code twice to ensure that the the MERGE processing occurs. That is, the newly created node will have a createdAt property and the updated node will have a matchedAt property. In both cases, the node will have the updatedAt property set
THE QUERY NEEDS TO LOOK LIKE THIS IN Neo4J
MERGE (m:Movie {title: ‘Rocketman’})
// perform the ON MATCH setting of the matchedAt property
// perform the ON CREATE setting of the createdAt property
// set the updatedAt property
RETURN m
I actually have the query below! But there is some issue with the node. Please help me fix it!
MERGE (m:Movie {title: ‘Rocketman’})ON MATCH
SET m.matchedAT = datetime(),
m.updatedAt = datetime()
ON CREATE
SET m.createdAt = datetime(),
m.updatedAt = datetime()
RETURN m.title, m.createdAt,m.matchedAt, m.updatedAt