Clone nodes

The available procedures are described in the table below:

call apoc.refactor.cloneNodes([node1,node2,…​])

clone nodes with their labels and properties

call apoc.refactor.cloneNodesWithRelationships([node1,node2,…​])

clone nodes with their labels, properties and relationships

Example Usage

The examples below will help us learn how to use these procedures.

Clone nodes only

The following creates a graph with two nodes, Foo and Bar:
CREATE (f:Foo{name:'Foo'}),(b:Bar{name:'Bar'})
The following creates copies of both of these nodes:
MATCH (f:Foo{name:'Foo'}),(b:Bar{name:'Bar'})
CALL apoc.refactor.cloneNodes([f,b])
YIELD input, output

If we execute this query, it will result in the following graph:


Clone nodes with relationships

The following creates a graph containing two different nodes of type Actor connected with other two different node of type Movie
CREATE (k:Actor {name:'Keanu Reeves'})-[:ACTED_IN {role:'Neo'}]->(m:Movie {title:'The Matrix'}),
       (t:Actor {name:'Tom Hanks'})-[:ACTED_IN {role:'Forrest'}]->(f:Movie {title:'Forrest Gump'})
The following creates copies of both of these nodes and their relationships:
MATCH (k:Actor {name:'Keanu Reeves'}), (t:Actor {name:'Tom Hanks'})
CALL apoc.refactor.cloneNodesWithRelationships([k,t])
YIELD input, output

As result we have a copy of the nodes and relationships