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.

Node property clean up - mass changing node keys

Jason_L
Node Link

Greetings all,
Using neo4j and really enjoying its flexibility. I've been using imported data and I'm trying to perform some data clean up and I was looking for a means to mass edit all my property keys on a set of nodes. In my case, I want to make all the keys(n) upper case and replace blanks with "_" regardless of the column name.

The following sets does this but assumes you know the specific name of the key.

MATCH (c:Category)
UNWIND keys = collKeys
SET c.COMPANY = c.Company   
REMOVE c.Company
return c limit 1000

The following builds out a list of current keys and then what I want the labels to be. I'm just not sure how to adjust the SET correctly.
I'm trying to find a way to perform something like the following to UPPER CASE all my keys(c)

//SET c.REPLACE(toUPPER(c.Company)," ", "") = REPLACE(toUPPER(c.Company)," ", "")

MATCH (c:Category)
UNWIND keys(c) as collKeys
WITH DISTINCT collKeys
WITH collKeys, REPLACE(toUPPER(collKeys)," ", "_") as collUPPERKeys
WHERE collKeys <> 'source'
SET c.collUPPERKeys = REPLACE(toUPPER(c.collKeys)," ", "_")    //<-- this is where I'm struggling as c.collUPPERKeys doesn't make sense
REMOVE c.collKeys
return  c

Is there an apoc function might be able to do this?

I realize best practice would be to do this at import but I don't have access to that code as of yet though I intend to do this prior to moving into the neo4j dbase.

Many thanks in advance

1 REPLY 1

Jason_L
Node Link

Found apoc functions to do this

First use apoc.create.setProperty()
to add the renamed property

Second, use apoc.create.removeProperties() to remove the prior property name.