简体   繁体   English

如何使用py2neo将字典作为一个属性值存储到neo4j中节点的单个属性键?

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

I have a node and I want to add one property property_x whose value I want to be {"year1":value, "year2":value} . 我有一个节点,我想添加一个属性property_x其值我想成为{"year1":value, "year2":value} Making more than one node for each year is not needed as I need these values in my processing together. 不需要每年制作一个以上的节点,因为我在一起处理时需要这些值。

Neo4j only supports certain kinds of properties ( docs ): Neo4j仅支持某些类型的属性( 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 . 数字:容量为Java的Long类型的整数值和容量为Java的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. 您可以尝试使用json.dumps将字典转换为JSON字符串并存储该字符串。 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. 但是,这将意味着您在编写查询时无法轻松使用对象的内容,并且需要json.loads在检索节点时将数据json.loads回。

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. 或者,您可以使对象成为具有属性year1year2等的单独节点,并将其链接到具有关系的第一个节点。

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

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