Zar Ashouri
Zar Ashouri

Reputation: 184

delete and update properties of neo4j nodes

this post is actually for ensuring about correctness of a cypher query. Assume you want to remove misspelled properties from all nodes and set value of those into new property, e.g like this:

match (u:User) set u.username = u.userrname remove u.userrname

As I noticed, it will check all nodes in label User whether it has property userrname, if exists it would set new property username with existing value and then remove the userrname. else, nothing would happen.

Am I right?

Upvotes: 0

Views: 552

Answers (1)

Graphileon
Graphileon

Reputation: 5385

The cypher you use would set username to null in case userrname does not exist.

So you have to limit your MATCH to the nodes where userrname exists

MATCH (u:User) 
WHERE EXISTS(u.userrname)

SET u.username = u.userrname 
REMOVE u.userrname

Upvotes: 1

Related Questions