apoc.create.setProperty
Syntax |
|
||
Description |
Sets the given property to the given |
||
Input arguments |
Name |
Type |
Description |
|
|
The nodes to set a property on. |
|
|
|
The name of the property key to set. |
|
|
|
The value of the property to set. |
|
Return arguments |
Name |
Type |
Description |
|
|
The updated node. |
Set Properties using Cypher
Properties can be referenced dynamically in Cypher without using Cypher.
SET n[key]
The dynamically calculated key must evaluate to a STRING
value.
For more information, see the Cypher Manual → Dynamically setting or updating a property.
Usage Examples
The examples in this section are based on the following sample graph:
CREATE (stop:Stop {arrival: "0802", departure: "0803"});
We want to convert the arrival
and departure
properties into Time types and store them as new properties, whose names are based on the original property keys.
We can generate the new property keys and Time values, by running the following query:
MATCH (stop:Stop)
UNWIND ["arrival", "departure"] AS key
RETURN key + "Time" AS newKey, time(stop[key]) AS time;
newKey |
---|
time |
"arrivalTime" |
08:02Z |
"departureTime" |
08:03Z |
Using apoc.create.setProperty
:
MATCH (stop:Stop)
UNWIND ["arrival", "departure"] AS key
WITH stop, key + "Time" AS newKey, time(stop[key]) AS time
CALL apoc.create.setProperty(stop, newKey, time)
YIELD node
RETURN node;
node |
---|
(:Stop {departure: "0803", arrival: "0802", arrivalTime: 08:02Z}) |
(:Stop {departureTime: 08:03Z, departure: "0803", arrival: "0802", arrivalTime: 08:02Z}) |
The Cypher equivalent to this is:
MATCH (stop:Stop)
UNWIND ["arrival", "departure"] AS key
WITH stop, key + "Time" AS newKey, time(stop[key]) AS time
SET stop[newKey] = time
RETURN stop