Neo4j rename property using regex of current property value

此生再无相见时 提交于 2019-12-08 08:12:01

问题


From my research (lots of Googling), I can not see that this is possible, but it is still worth asking I think. I have a large collection of nodes like:

(org:Organization {name: "Organization 1234"})

where 1234 can be any non-negative integer.

In order to update the DB to work with a new API, I am wanting to rename each of these in the collection so that the result would look something like:

(org:Organization {name: "Org_1234"})

So, I need to mashup Org_ with the [0-9]+ regex match on the current property.

Truly, I am at a loss on where to even start. All I see in the documentation is that regex can be used as a predicate in the WHERE clause (WHERE n.property =~ {regex}). Is there a way using just Cypher as I am not using a Java library?


回答1:


Assuming there is always a single space between "Organization" and the integer, you can brute force this pretty easily with just string functions.

CREATE (:Organization {name:'Organization 1234'}), 
       (:Organization {name:'Organization 5678'})

MATCH (o:Organization)
WITH o, SPLIT(o.name, " ")[1] AS id
SET o.name = "Org_" + id
RETURN o.name

Which returns

o.name
Org_1234
Org_5678


来源:https://stackoverflow.com/questions/24087753/neo4j-rename-property-using-regex-of-current-property-value

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!