atkayla
atkayla

Reputation: 8859

How to rename a label while maintaining its nodes' relationships, and merge it into another label?

I made a mistake on my server where my nodes were saving as :Studio instead of :GameStudio like I wanted them to.

Now my database has both :Studio and :GameStudio nodes, however I'd really like to rename all of the :Studio nodes.

Is there a query I can write that will rename the :Studio (while maintaining their relationships) and merge them into :GameStudio? :Studio and :GameStudio have the same properties and unique by id.

Upvotes: 4

Views: 3853

Answers (1)

InverseFalcon
InverseFalcon

Reputation: 30407

This is very easy. Here's the query to do this:

MATCH (s:Studio)
SET s:GameStudio
REMOVE s:Studio

Also, you may not know this, but nodes can have multiple labels, which is very useful if certain labels are more specific versions of other labels, or if the same nodes need to be shared between different domains using different labels.

It may be helpful to keep the Cypher refcard on hand, especially if you're new to Neo4j and Cypher.

Upvotes: 11

Related Questions