1

Im using bulbs to handle neo4j operations in python. The problem is when I try to create a node with a property containing a dictionary:

g.mynode.create(title='Mi Node', fields={'name': 'testNode'})

I end up getting the following error:

*** SystemError: ({'status': '200', 'content-length': '109', 'content-encoding':
 'UTF-8', 'server': 'Jetty(6.1.25)', 'access-control-allow-origin': '*', 'content-
 type': 'application/json'}, '"java.lang.IllegalArgumentException:
 Unknown property type on: {name=testNode}, class java.util.LinkedHashMap"')
Rod0n
  • 1,019
  • 2
  • 14
  • 33

1 Answers1

0

Neo4j doesn't support dictionaries, and it only supports lists that contain primitive types such as string, int, bool, etc (mixed types in a list aren't allowed).

Here are the property types Neo4j supports:

http://docs.neo4j.org/chunked/preview/graphdb-neo4j-properties.html

To store a dictionary in Neo4j, you can save it as a JSON string.

Bulbs has a Document Property type that does the dict<->json conversion for you.

See...

If you working with a generic Vertex or Edge, you need to do this conversion manually before you save it:

type_system = g.client.type_system
fields = type_system.database.to_document({'name': 'testNode'})
g.mynode.create(title='Mi Node', fields=fields)

However, if you using a Model, Bulbs will do the conversion for you. Simply define your model using the Document property instead of Dictionary:

# people.py

from bulbs.model import Node, Relationship
from bulbs.property import String, DateTime, Document
from bulbs.utils import current_datetime

    class Person(Node):

        element_type = "person"

        name = String(nullable=False)
        fields = Document()

    class Knows(Relationship):

        label = "knows"

        timestamp = DateTime(default=current_datetime, nullable=False)

...you can then use your model like this...

>>> from people import Person, Knows
>>> from bulbs.neo4jserver import Graph

>>> g = Graph()
>>> g.add_proxy("people", Person)
>>> g.add_proxy("knows", Knows)

>>> james = g.people.create(name="James", fields={'name': 'testNode1'})
>>> julie = g.people.create(name="Julie", fields={'name': 'testNode2'})
>>> knows = g.knows.create(james, julie)

See http://bulbflow.com/docs/api/bulbs/model/

espeed
  • 4,754
  • 2
  • 39
  • 51