Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
12-15-2020 08:57 PM
Is there a way to replace a node with another existing one in neo4j, without having to delete all relationships, delete the old node, and reattach relationships to the new one?
E.g. I have an industry node called online retail that 3 company nodes point to. I want to "switch it out" with a sector node that is called retail. I want all 3 initial companies to point to this new sector retail node. Is there a way to do this, without detaching relationships from the industry node, deleting the industry node, and then adding each company/sector relationship back?
Thanks!
Solved! Go to Solution.
12-16-2020 05:47 AM
You don't delete the node, you just modify it in place. You can use SET/UNSET to change labels, and then just assign properties. You'd do it like this:
MATCH (x:Industry { name: "online retail" })
UNSET x:Industry
SET x:Sector, x.name = "retail"
When you do this, the relationships don't get touched. I would not advise deleting / recreating the node, because then you would have to rewire the relationships.
12-16-2020 05:47 AM
You don't delete the node, you just modify it in place. You can use SET/UNSET to change labels, and then just assign properties. You'd do it like this:
MATCH (x:Industry { name: "online retail" })
UNSET x:Industry
SET x:Sector, x.name = "retail"
When you do this, the relationships don't get touched. I would not advise deleting / recreating the node, because then you would have to rewire the relationships.
All the sessions of the conference are now available online