简体   繁体   中英

How to create label on py2neo object using Object-Graph-Mapping before saved in Neo4j database

I am trying to save a node with a label but i can't. Only node with properties will save on neo4j db. I appreciate if anyone can help with how to create a label on an object before i save it. I am using python and django with py2neo object-graph mapping for neo4j db. Here is the code. (In cypher this could be achieved using CREATE (n:Person{ id : id#, displayName : 'My Name' }) but i want to use py2neo object-graph mapping.)

In model.py I have

class Person(object):

    def __init__(self, id=None, displayName=None):
        self.id = id
        self.displayName = displayName

    def __str__(self):
        return self.displayName

in another .py file i have

from py2neo import neo4j
from py2neo import ogm
graph_db = neo4j.GraphDatabaseService("http://localhost:7474/db/data/")`

def addPeople():
    store = ogm.Store(graph_db)
    worker = model.Person(1, "My Name")
    store.save_unique("People","ID",worker.id,worker)`

Here the node will be created with id and dispalyName property, but not with label.

The OGM module was initially designed before the label/schema functionality was added to Neo4j. Therefore it is unaware of labels and schema indexes in general and uses legacy indexing instead. Make sure you are familiar with the differences between these two types of index:

The REST API interface does not easily lend itself to creating nodes with label detail in one request so this is not an easily change to make. I may rework the OGM module in future to support labels and schema indexes instead but for your application, you probably want to look at Cypher instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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