Skip to content Skip to sidebar Skip to footer

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}. Making more than one node for each year is not needed as I need the

Solution 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.

Post a Comment for "How Can I Use Py2neo To Store A Dictionary As One Property Value To Single Property Key Of A Node In Neo4j?"