apoc.create.setRelProperty过程Cypher 25 中已弃用
|
此过程已弃用。如需动态设置属性,请改用 Cypher 的 |
语法 |
|
||
描述 |
在 |
||
输入参数 |
名称 |
类型 |
描述 |
|
|
要设置属性的关系。 |
|
|
|
要设置的属性键的名称。 |
|
|
|
要设置的属性值。 |
|
返回参数 |
名称 |
类型 |
描述 |
|
|
更新后的关系。 |
|
使用 Cypher 设置属性
无需使用 APOC,即可在 Cypher 中动态引用属性。
用于在节点或关系上动态设置属性的 Cypher 语法
SET n[key]
动态计算的键必须求值为 STRING(字符串)值。有关更多信息,请参阅 Cypher 手册 → 动态设置或更新属性。
使用示例
本节中的示例基于以下示例图
CREATE (station1:Station {name: "Station 1"})
CREATE (station2:Station {name: "Station 3"})
CREATE (station1)-[:JOURNEY {arrival: "0802", departure: "0803"}]->(station2);
我们希望将 arrival(到达)和 departure(出发)属性转换为时间类型,并将它们存储为新属性,其名称基于原始属性键。
我们可以通过运行以下查询来生成新的属性键和时间值
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 |
使用 apoc.create.setRelProperty 或仅使用 Cypher
apoc.create.setRelProperty
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;
使用 Cypher 的动态属性
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
| 关系 |
|---|
[:JOURNEY {departure: "0803", arrival: "0802", arrivalTime: 08:02Z}] |
[:JOURNEY {departureTime: 08:03Z, departure: "0803", arrival: "0802", arrivalTime: 08:02Z}] |