user3777228
user3777228

Reputation: 159

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?

Upvotes: 3

Views: 3313

Answers (1)

Stefan Armbruster
Stefan Armbruster

Reputation: 39905

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.

Upvotes: 5

Related Questions