简体   繁体   中英

Change property data type in Neo4j using spring-data-neo4j

For a NodeEntity with any property(indexed or not - indexed), I wish to change the data type from Integer to String due to some use-case.
I simply changed the datatype in the defined NodeEntity class. The new data gets inserted into the database successfully with the data type of the property as the newly set(ie.String). However, the data type of the property for the nodes already in the database before this change remain as the old data type(ie Integer).
Is there any way to modify the datatype for all the nodes present in the database?

Cypher has couple of functions for this:

  • toInt : convert a string to a integer/long value
  • toFloat : convert a string to a floating point value
  • str : convert something to a string

With that you can easily modify the datatypes of existing properties. Assume you have a entity of type Person having a numeric zipCode property. You want to convert zipCode to a string:

MATCH (node:Person)
SET node.zipCode = str(node.zipCode)

If you have a large number of entities of that type make sure your transactions don't grow too large my using SKIP and LIMIT .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM