apoc.create.setRelProperties

Details

Syntax

apoc.create.setRelProperties(rels, keys, values) :: (rel)

Description

Sets the given properties on the RELATIONSHIP values.

Input arguments

Name

Type

Description

rels

ANY

The relationships to set properties on.

keys

LIST<STRING>

The keys of the properties to set on the given relationships.

values

LIST<ANY>

The values of the properties to set on the given relationships.

Return arguments

Name

Type

Description

rel

RELATIONSHIP

The updated relationship.

Set Properties using Cypher

Properties can be referenced dynamically in Cypher without using APOC.

Cypher syntax for dynamically setting a property on a node or a relationship
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 (jennifer:Person {name: "Jennifer", community: 1, partition: 4})
CREATE (karin:Person {name: "Karin", community: 4, partition: 2})
CREATE (elaine:Person {name: "Elaine", community: 3, partition: 3})
MERGE (jennifer)-[:FRIENDS {since: datetime("2019-06-01")}]-(karin)
MERGE (jennifer)-[:FRIENDS {since: datetime("2019-05-04")}]-(elaine);

We can duplicate all relationship properties, by running the following query:

MATCH (:Person)-[friends:FRIENDS]->(:Person)
WITH friends, keys(friends) AS keys
CALL apoc.create.setRelProperties(friends,[k in keys | k + "Copy"], [k in keys | friends[k]])
YIELD rel
RETURN startNode(rel).name AS start, rel, endNode(rel).name AS end;
Results
start rel end

"Jennifer"

[:FRIENDS {sinceCopy: 2019-05-04T00:00Z, since: 2019-05-04T00:00Z}]

"Elaine"

"Jennifer"

[:FRIENDS {sinceCopy: 2019-06-01T00:00Z, since: 2019-06-01T00:00Z}]

"Karin"

The Cypher equivalent to this is:

MATCH (p1:Person)-[friends:FRIENDS]->(p2:Person)
FOREACH (k IN keys(friends) | SET friends[k + "Copy"] = friends[k])
RETURN DISTINCT p1.name AS start, friends, p2.name AS end;