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/