apoc.create.removeRelProperties

Details

Syntax

apoc.create.removeRelProperties(rels, keys) :: (rel)

Description

Removes the given properties from the given RELATIONSHIP values.

Input arguments

Name

Type

Description

rels

ANY

The relationships to remove properties from.

keys

LIST<STRING>

The property keys to remove from the given nodes.

Return arguments

Name

Type

Description

rel

RELATIONSHIP

The updated relationship.

Remove Properties using Cypher

Properties can be referenced dynamically in Cypher without using APOC.

Cypher syntax for dynamically removing a property from a node or a relationship
REMOVE n[key]

The dynamically calculated key must evaluate to a STRING value. For more information, see the Cypher Manual → Dynamically removing 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 delete all properties from relationships, by running the following query:

CALL db.propertyKeys()
YIELD propertyKey
WITH collect(propertyKey) AS propertyKeys
MATCH (:Person)-[friends:FRIENDS]->(:Person)
WITH collect(friends) AS friendsRels, propertyKeys
CALL apoc.create.removeRelProperties(friendsRels, propertyKeys)
YIELD rel
RETURN startNode(rel).name AS start, rel, endNode(rel).name AS end;
Results
start rel end

"Jennifer"

[:FRIENDS]

"Elaine"

"Jennifer"

[:FRIENDS]

"Karin"

The Cypher equivalent to this is:

MATCH (p1:Person)-[friends:FRIENDS]->(p2:Person)
FOREACH(key IN keys(friends) | REMOVE friends[key])
RETURN DISTINCT p1.name AS start, friends, p2.name AS end;