apoc.refactor.cloneNodes

Details

Syntax

apoc.refactor.cloneNodes(nodes [, withRelationships, skipProperties ]) :: (input, output, error)

Description

Clones the given NODE values with their labels and properties. It is possible to skip any NODE properties using skipProperties (note: this only skips properties on NODE values and not their RELATIONSHIP values).

Input arguments

Name

Type

Description

nodes

LIST<NODE>

The nodes to be cloned.

withRelationships

BOOLEAN

Whether or not the connected relationships should also be cloned. The default is: false.

skipProperties

LIST<STRING>

Whether or not to skip the node properties when cloning. The default is: [].

Return arguments

Name

Type

Description

input

INTEGER

The internal id of the original entity.

output

NODE

The copied entity.

error

STRING

Any error that occurred during the copy process.

Refactoring nodes using Cypher

Node labels can be referenced dynamically in Cypher without using APOC.

Cypher syntax for creating, matching, and merging labels dynamically
CREATE (n1:$(label))
MERGE (n1:$(label))
MATCH (n1:$(label))

The dynamically calculated label must evaluate to a STRING or LIST<STRING>. For more information, see the Cypher Manual → CREATE, MERGE, MATCH.

Usage Examples

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

CREATE (mark:Person {name: "Mark", city: "London"})
CREATE (jennifer:Person {name: "Jennifer", city: "St Louis"})

The following examples create copies of all Person nodes using both APOC and Cypher:

apoc.refactor.cloneNodes
MATCH (p:Person)
WITH collect(p) AS people
CALL apoc.refactor.cloneNodes(people)
YIELD input
MATCH (p:Person)
RETURN DISTINCT p
Using Cypher’s dynamic labels
MATCH (p:Person)
CREATE (n:$(labels(p)))
SET n = properties(p)
WITH *
MATCH (p:Person)
RETURN DISTINCT p
Results
p

(:Person {name: "Mark", city: "London"})

(:Person {name: "Jennifer", city: "St Louis"})

(:Person {name: "Mark", city: "London"})

(:Person {name: "Jennifer", city: "St Louis"})