apoc.refactor.rename.nodeProperty

Details

Syntax

apoc.refactor.rename.nodeProperty(oldName, newName [, nodes, config ]) :: (batches, total, timeTaken, committedOperations, failedOperations, failedBatches, retries, errorMessages, batch, operations, constraints, indexes)

Description

Renames the given property from oldName to newName for all NODE values. If a LIST<NODE> is provided, the renaming is applied to the NODE values within this LIST<NODE> only.

Input arguments

Name

Type

Description

oldName

STRING

The property to rename.

newName

STRING

The new name to give the property.

nodes

LIST<NODE>

The nodes to apply the new name to. If this list is empty, all nodes with the old property name will be renamed. The default is: [].

config

MAP

{ batchSize = 100000 :: INTEGER, concurrency :: INTEGER, retries = 0 :: INTEGER, parallel = true :: BOOLEAN, batchMode = "BATCH" :: STRING } The default is: `{}.

Return arguments

Name

Type

Description

batches

INTEGER

The number of batches the operation was run in.

total

INTEGER

The total number of renamings performed.

timeTaken

INTEGER

The time taken to complete the operation.

committedOperations

INTEGER

The total number of committed operations.

failedOperations

INTEGER

The total number of failed operations.

failedBatches

INTEGER

The total number of failed batches.

retries

INTEGER

The total number of retries.

errorMessages

MAP

The collected error messages.

batch

MAP

{ total :: INTEGER, failed :: INTEGER, committed :: INTEGER, errors :: MAP }

operations

MAP

{ total :: INTEGER, failed :: INTEGER, committed :: INTEGER, errors :: MAP }

constraints

LIST<STRING>

Constraints associated with the given label or type.

indexes

LIST<STRING>

Indexes associated with the given label or type.

Setting and removing properties using Cypher

Properties can be referenced dynamically in Cypher without using APOC.

Cypher syntax for dynamically setting and removing a property from a node or a relationship
SET n[key] = <expr>
REMOVE n[key]

The dynamically calculated key must evaluate to a STRING value. For more information, see the Cypher Manual → Dynamically set or update a property and Cypher Manual → Dynamically removing a property.

Usage Examples

The examples in this section are based on the following sample graph:

CREATE (mark:DevRel {name: "Mark", city: "London"})
CREATE (jennifer:DevRel {name: "Jennifer", city: "St Louis"})
CREATE (michael:DevRel {name: "Michael", city: "Dresden"})
CREATE (jim:Engineer {name: "Jim", city: "London"})
CREATE (alistair:Engineer {name: "Alistair", city: "London"})

The following query changes the node property city to location for all nodes with the DevRel label using both APOC and Cypher:

apoc.refactor.rename.nodeProperty
MATCH (person:DevRel)
WITH collect(person) AS people
CALL apoc.refactor.rename.nodeProperty("city", "location", people)
YIELD total
RETURN total
Using Cypher
MATCH (person:DevRel)
SET person.location = person.city
REMOVE person.city
RETURN count(*) AS total
Results
total

3

The following query returns all the nodes in our graph after this refactoring has been done:

MATCH (n)
RETURN (n)
Results
n

(:DevRel {name: "Jennifer", location: "St Louis"})

(:DevRel {name: "Michael", location: "Dresden"})

(:Engineer {city: "London", name: "Jim"})

(:DevRel {name: "Mark", location: "London"})

(:Engineer {city: "London", name: "Alistair"})

This procedure does not rename the property; it creates a new property with the new name and copies the value from the original property, which is then deleted.