apoc.create.removeProperties

Details

Syntax

apoc.create.removeProperties(nodes, keys) :: (node)

Description

Removes the given properties from the given NODE values.

Input arguments

Name

Type

Description

nodes

ANY

The nodes to remove properties from.

keys

LIST<STRING>

The property keys to remove from the given nodes.

Return arguments

Name

Type

Description

node

NODE

The updated node.

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 except for name from Person nodes, by running the following query:

CALL db.propertyKeys()
YIELD propertyKey WHERE propertyKey <> "name"
WITH collect(propertyKey) AS propertyKeys
MATCH (p:Person)
WITH collect(p) AS nodes, propertyKeys
CALL apoc.create.removeProperties(nodes, propertyKeys)
YIELD node
RETURN node;
Results
node

(:Person {name: "Jennifer"})

(:Person {name: "Karin"})

(:Person {name: "Elaine"})

The Cypher equivalent to this is:

CALL db.propertyKeys()
YIELD propertyKey WHERE propertyKey <> "name"
WITH collect(propertyKey) AS propertyKeys
MATCH (p:Person)
FOREACH(key IN propertyKeys | REMOVE p[key])
RETURN DISTINCT p;