Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Neo4J: Renaming property keys

Tags:

I just got started on Neo & tried to look for prior questions on this topic. I need help to rename one of the property keys.

I created the following node:

CREATE (Commerce:Category {title:' Commerce', Property:'Category', Owner:'Magic Pie', Manager:'Simple Simon'})

Now want to rename title to name. Is there a way to do it? I don't want to delete the node as there are 100's of nodes with the property "title".

like image 288
kkulkarn Avatar asked Feb 19 '15 22:02

kkulkarn


People also ask

What are property keys in Neo4j?

propkeys — Property keys Property keys in the Neo4j database, returned as a cell array of character vectors. Each character vector denotes a property key.

How do I change my relationship name in Neo4j?

You cannot rename an already existing relationship. You'd have to run through all relationships, create the new one in parallel (including all properties) and then remove the old one.

Is Neo4j key-value?

(b) Use Neo4j, by creating a node per key-value setting the key and value as properties on the node, but there is no relationship other then having an index to group these nodes together, exposing the key of the key-value as the key on the index.

How do you create a relationship between two nodes in Neo4j?

To create a relationship between two nodes, we first get the two nodes. Once the nodes are loaded, we simply create a relationship between them. The created relationship is returned by the query.


1 Answers

Yes, you want to SET a new property name with the value of the old property title. And then REMOVE the old property title. Something like this...

MATCH (c:Category)
WHERE c.name IS NULL
SET c.name = c.title
REMOVE c.title

If you have MANY nodes, it is advisable to perform the operation in smaller batches. Here is an example of limiting the operation to 10k at a time.

MATCH (c:Category)
WHERE c.name IS NULL
WITH c
LIMIT 10000
SET c.name = c.title
REMOVE c.title
like image 183
Dave Bennett Avatar answered Oct 06 '22 02:10

Dave Bennett