Check your understanding
1. Creating, adding, removing properties
Suppose you have a reference to a node. What keyword do you use to create, update, or remove a property of the referenced node?
-
❏
INSERT -
✓
SET -
❏
UPDATE PROPERTY -
❏
UPDATE
Hint
This clause can be used to remove a property by setting it to null.
Solution
You use the SET clause to set a value to null in the graph.
2. Creating properties
What are the ways that you can add a property to a node or relationship?
-
✓ When you create it using
MERGEwhere you specify the property in braces {..}. -
❏ Create an index for it by its property key.
-
❏ Use the
ADD PROPERTYclause if you have a reference to the node or relationship. -
✓ Use the
SETclause if you have a reference to the node or relationship.
Hint
There are two ways to create properties, inline or setting them.
Solution
There are two ways to set property values in Cypher:
-
Specify the property values in the {..} when you create the node or relationship.
-
Use the
SETclause to set values to a reference to the node or relationship.
You do not create an index to set property values.
There is no ADD PROPERTY clause in Cypher.
3. Removing properties
Suppose we want to remove all tagline properties from all Movie nodes in the graph.
Use the dropdown below to complete the code.
MATCH (m:Movie)
/*select:REMOVE m.tagline*/
RETURN m-
❏
REMOVE tagline -
❏
DELETE m.tagline -
✓
REMOVE m.tagline -
❏
DELETE tagline
Once you have selected your option, click the Check Results query button to continue.
Hint
This MATCH clause will select all Movie nodes in the graph and reference it with the variable m.
What clause do you use the remove the property for every node retrieved.
Solution
REMOVE m.tagline is the correct answer. We have a reference to the Movie node so we can use the REMOVE clause to remove the property.
REMOVE tagline is incorrect, because we do not have a reference to the node.
There is no DELETE clause in Cypher.
Summary
In this lesson, you learned how to create, update and delete properties for nodes and relationships. In the next challenge, you will add properties to a node.