How can I use py2neo to store a dictionary as one property value to single property key of a node in neo4j?

▼魔方 西西 提交于 2020-06-03 01:48:30

问题


I have a node and I want to add one property property_x whose value I want to be {"year1":value, "year2":value}. Making more than one node for each year is not needed as I need these values in my processing together.


回答1:


Neo4j only supports certain kinds of properties (docs):

...there are restrictions as to what types of values can be used as property values. Allowed value types are as follows:

  • Numbers: Both integer values, with capacity as Java’s Long type, and floating points, with capacity as Java’s Double.

  • Booleans.

  • Strings.

  • Arrays of the basic types above.

You therefore cannot set a dictionary as a property. You could try using json.dumps to convert the dictionary to a JSON string and storing the string. However, this will mean that you cannot easily use the content of the object when writing queries, and will need to json.loads the data back when you retrieve the node.

Alternatively, you could make the object a separate node with the properties year1, year2, etc., and link it to the first node with a relationship.



来源:https://stackoverflow.com/questions/38025955/how-can-i-use-py2neo-to-store-a-dictionary-as-one-property-value-to-single-prope

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