cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Set property before cloning nodes

mkretsch
Node Clone

I am cloning a group of nodes, but before doing so, I want to write a new property SET n.uuid = n.uuidoriginal, but I am having troubles then with collect. This way the input and output cloned nodes have different uuid, but the same uuidoriginal. Any ideas?

MATCH (n) WHERE id(n) in {{"My nodes":nodeset}}
WITH collect(n) as nodes
CALL apoc.refactor.cloneNodes(nodes, true, ["uuid"])
YIELD input, output
SET output:Merged
SET output.uuid = apoc.create.uuid()
return input, output

1 ACCEPTED SOLUTION

Try this:

MATCH (n) WHERE id(n) in [1]
WITH collect(n) as nodes
FOREACH(i in nodes | SET i.uuidoriginal = i.uuid)
WITH nodes
CALL apoc.refactor.cloneNodes(nodes, true, ["uuid"])
YIELD input, output
SET output:Merged
SET output.uuid = apoc.create.uuid()
return input, output

I think you reversed the SET expression. Do you want to preserve the original uuid, so it would be in both nodes? I changed the code just in case, so it preserves the original uuid in the i.uuidoriginal attribute.

View solution in original post

2 REPLIES 2

Try this:

MATCH (n) WHERE id(n) in [1]
WITH collect(n) as nodes
FOREACH(i in nodes | SET i.uuidoriginal = i.uuid)
WITH nodes
CALL apoc.refactor.cloneNodes(nodes, true, ["uuid"])
YIELD input, output
SET output:Merged
SET output.uuid = apoc.create.uuid()
return input, output

I think you reversed the SET expression. Do you want to preserve the original uuid, so it would be in both nodes? I changed the code just in case, so it preserves the original uuid in the i.uuidoriginal attribute.

This works great! I had a hunch it would come down to FOREACH, but was not very sure. Thank you!