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.

Deleting keys using a wildcard

Through an annoying program error, we ended up with a bunch of keys in the database that all start with AMS. When I look at the attributes, I see AMS001, AMS002, AMS003 - sadly its random also so we have an AMS8012 etc. If it was just sequential, I would do it in excel !

Is there a nice way to remove attributes that have 'AMS' as the first 3 characters ?
Deleting them one at a time (match (a) remove a.AMS001;) when there are thousands, is painful.

1 ACCEPTED SOLUTION

the blog post includes sample code of

CALL db.propertyKeys() YIELD propertyKey WHERE propertyKey <> 'name'
WITH collect(propertyKey) AS properties
MATCH (n:Node)
WITH collect(n) AS nodes, properties
CALL apoc.create.removeProperties(nodes, properties)
YIELD node
RETURN count(*)

which is to find all properties which do not have a name of 'name'. i.e. if you had 6 properties of

name, age, gender, address, city, state

then

CALL db.propertyKeys() YIELD propertyKey WHERE propertyKey <> 'name'
WITH collect(propertyKey) AS properties

would result in the variable properties being defined as [age, gender, address, city, state].

But using this as an example you could simply change line 1-2 above to

CALL db.propertyKeys() YIELD propertyKey WHERE propertyKey starts with 'AMS'
WITH collect(propertyKey) AS properties

and then the variable properties would be defined as [AMS01, AMS02, AMS883, AMS7373, AMS634] etc

View solution in original post

4 REPLIES 4

Neo4j: Delete/Remove dynamic properties · Mark Needham also provides examples how to do this using APOC

Unless I am missing something, this does a great job explaining how to eliminate the keys, but i either need to specify all the keys I don't want to remove ( non trivial as well) or the ones I do want to remove. But it doesn't let me do it for partial keys (e.g substring(a.key, 3) = 'AMS')

Did I miss that ?

the blog post includes sample code of

CALL db.propertyKeys() YIELD propertyKey WHERE propertyKey <> 'name'
WITH collect(propertyKey) AS properties
MATCH (n:Node)
WITH collect(n) AS nodes, properties
CALL apoc.create.removeProperties(nodes, properties)
YIELD node
RETURN count(*)

which is to find all properties which do not have a name of 'name'. i.e. if you had 6 properties of

name, age, gender, address, city, state

then

CALL db.propertyKeys() YIELD propertyKey WHERE propertyKey <> 'name'
WITH collect(propertyKey) AS properties

would result in the variable properties being defined as [age, gender, address, city, state].

But using this as an example you could simply change line 1-2 above to

CALL db.propertyKeys() YIELD propertyKey WHERE propertyKey starts with 'AMS'
WITH collect(propertyKey) AS properties

and then the variable properties would be defined as [AMS01, AMS02, AMS883, AMS7373, AMS634] etc

Thank you - yes, that did it I think. They still show up on the database information side but I assume that will eventually go away. Thank you