Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
04-14-2022 10:04 AM
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
Solved! Go to Solution.
04-14-2022 10:25 AM
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.
04-14-2022 10:25 AM
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.
04-14-2022 10:37 AM
This works great! I had a hunch it would come down to FOREACH, but was not very sure. Thank you!
All the sessions of the conference are now available online