Set
This page describes how to create SET clauses.
Append SET statements to a clause with the method .set.
Update properties with SET
You can update properties of a node or relationship with the .set method.
For example, to update the properties of a node:
const personNode = new Cypher.Node();
const matchQuery = new Cypher.Match(new Cypher.Pattern(personNode, { labels: ["Person"] })).set(
[personNode.property("name"), new Cypher.Param("Keanu")],
);
This generates the following Cypher®:
MATCH (this0:Person)
SET
this0.name = $param1
RETURN this0
You can pass multiple pairs of property expressions to update multiple properties:
const personNode = new Cypher.Node();
const matchQuery = new Cypher.Match(new Cypher.Pattern(personNode, { labels: ["Person"] })).set(
[personNode.property("name"), new Cypher.Param("Keanu")],
[personNode.property("year"), new Cypher.Param(1999)]
);
This generates the following Cypher®:
MATCH (this0:Person)
SET
this0.name = $param1,
this0.year = $param2
RETURN this0
Use SET to replace all node properties
To update all the properties of a node or relationship, instead of a property, pass the variable directly as the first element of the array.
The second element must be a Cypher®.Map or a variable:
const personNode = new Cypher.Node();
const matchQuery = new Cypher.Match(new Cypher.Pattern(personNode, { labels: ["Person"] })).set([
personNode, new Cypher.Map({
name: new Cypher.Param("Keanu"),
year: new Cypher.Param(1999)
})
]);
This generates the following Cypher®:
CREATE (this0:Movie)
SET
this0 = { title: $param0, year: $param1 }
When using a node:
const matchQuery = new Cypher.Match(new Cypher.Pattern(personNode, { labels: ["Person"] })).set([
personNode, anotherPersonNode
]);
CREATE (this1:Movie)
SET
this1 = this0
The += operator
When passing a map to update a node properties with SET, it is possible to use the operator += to add new properties, instead of replacing them:
const personNode = new Cypher.Node();
const matchQuery = new Cypher.Match(new Cypher.Pattern(personNode, { labels: ["Person"] })).set([
personNode, "+=", new Cypher.Map({
name: new Cypher.Param("Keanu"),
year: new Cypher.Param(1999)
})
]);
This generates the following Cypher®:
CREATE (this0:Movie)
SET
this0 += { title: $param0, year: $param1 }
SET with labels
You can use SET to update the labels of a node or the type of a relationship.
For more information, see How to update labels.