Maybe you already have a node or relationship in the data, but you want to modify its properties.
You can do this by matching the pattern you want to find and using the SET
keyword to add, remove, or update properties.
Using our example thus far, we could update Jennifer’s node to add her birthday.
The next Cypher statement shows how to do this.
First, we need to find our existing node for Jennifer.
Next, we use SET
to create the new property (with syntax variable.property
) and set its value.
Finally, we can return Jennifer’s node to ensure that the information was updated correctly.
MATCH (p:Person {name: 'Jennifer'})
SET p.birthdate = date('1980-01-01')
RETURN p
If we now wanted to change her birthday, we could use the same query above to find Jennifer’s node again and put a different date in the SET
clause.
We could also update Jennifer’s WORKS_FOR
relationship with her company to include the year that she started working there.
To do this, you can use similar syntax as above for updating nodes.
MATCH (:Person {name: 'Jennifer'})-[rel:WORKS_FOR]-(:Company {name: 'Neo4j'})
SET rel.startYear = date({year: 2018})
RETURN rel
This is a companion discussion topic for the original entry at https://neo4j.com/developer/cypher/reading-writing/