简体   繁体   English

使用spring-data-neo4j在Neo4j中更改属性数据类型

[英]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. 对于具有任何属性(索引或未索引)的NodeEntity,我希望由于某些用例而将数据类型从Integer更改为String。
I simply changed the datatype in the defined NodeEntity class. 我只是在已定义的NodeEntity类中更改了数据类型。 The new data gets inserted into the database successfully with the data type of the property as the newly set(ie.String). 新数据成功插入到数据库中,属性的数据类型为新设置的(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: Cypher有几个功能:

  • toInt : convert a string to a integer/long value toInt :将字符串转换为整数/长整数值
  • toFloat : convert a string to a floating point value toFloat :将字符串转换为浮点值
  • str : convert something to a string str :将某些东西转换为字符串

With that you can easily modify the datatypes of existing properties. 有了它,您可以轻松修改现有属性的数据类型。 Assume you have a entity of type Person having a numeric zipCode property. 假设您有一个具有数字zipCode属性的Person类型的实体。 You want to convert zipCode to a string: 您想将zipCode转换为字符串:

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 . 如果你有大量这种类型的实体,请确保你的交易不会变得太大我使用SKIPLIMIT

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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