How do I do the following in one cypher query?
- match a set of nodes
- clone them and their relationships
- change the label on the cloned nodes
I tried various versions of the code below but only the clone is created; the label is not renamed.
The code below is for one node with id = 'abc' to validate the procedures.
MATCH (n:OldLabel {id:'abc'})
WITH collect(n) as nodes
CALL apoc.refactor.cloneNodes(nodes,True) YIELD output as c
WITH collect(c) as clones
CALL apoc.refactor.rename.label("OldLabel","NewLabel",clones)
YIELD batches as b
RETURN clones
Running them separately works.
The end goal is to remove the filter on id(n) <> 123 and have both calls execute against all nodes with OldLabel. i.e. create a set of OldLabel, clone and rename them.
MATCH (n:OldLabel {id:'abc'})
WITH collect(n) as nodes
CALL apoc.refactor.cloneNodes(nodes,True) YIELD output as c
return c
if 123 is the original node, rename all others.
MATCH (n:OldLabel {id:'abc'})
WHERE id(n) <> 123
WITH collect(n) as clones
CALL apoc.refactor.rename.label("OldLabel","NewLabel",clones)
YIELD batches as b
RETURN clones