apoc.create.setRelProperty
Syntax |
|
||
Description |
Sets the given property on the |
||
Input arguments |
Name |
Type |
Description |
|
|
The relationships 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 relationship. |
Set Properties using Cypher
Properties can be referenced dynamically in Cypher without using APOC.
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 (station1:Station {name: "Station 1"})
CREATE (station2:Station {name: "Station 3"})
CREATE (station1)-[:JOURNEY {arrival: "0802", departure: "0803"}]->(station2);
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 (:Station)-[journey:JOURNEY]->(:Station)
UNWIND ["arrival", "departure"] AS key
RETURN key + "Time" AS newKey, time(journey[key]) AS time;
newKey | time |
---|---|
"arrivalTime" |
08:02Z |
"departureTime" |
08:03Z |
Using apoc.create.setRelProperty
or only Cypher:
MATCH (:Station)-[journey:JOURNEY]->(:Station)
UNWIND ["arrival", "departure"] AS key
WITH journey, key + "Time" AS newKey, time(journey[key]) AS time
CALL apoc.create.setRelProperty(journey, newKey, time)
YIELD rel
RETURN rel;
MATCH (:Station)-[journey:JOURNEY]->(:Station)
UNWIND ["arrival", "departure"] AS key
WITH stop, key + "Time" AS newKey, time(journey[key]) AS time
SET journey[newKey] = time
RETURN journey
rel |
---|
[:JOURNEY {departure: "0803", arrival: "0802", arrivalTime: 08:02Z}] |
[:JOURNEY {departureTime: 08:03Z, departure: "0803", arrival: "0802", arrivalTime: 08:02Z}] |