简体   繁体   English

Neo4j Py2neo不更新节点属性

[英]Neo4j Py2neo not updating node properties

Writing python program to fetch existing Neo4j node and update properties using py2neov3 package . 编写python程序来获取现有的Neo4j节点并使用py2neov3 package更新属性。

Movie node has title & year properties. 电影节点具有标题和年份属性。 Have a python dictionary with list of movies to be added. 有一个带有要添加电影列表的python字典。

I have tried below options, movie node is getting added. 我尝试了以下选项,正在添加电影节点。 But year property is not updated. 但是年份属性未更新。

Option#1: Use Py2neo OGM. 选项1:使用Py2neo OGM。 Start transaction, create Movie object, populate title, invoke merge, populate year, invoke push, finally commit 开始交易,创建Movie对象,填充标题,调用合并,填充年份,调用push,最后提交

Option#2: Instead of OGM (Commented code below), use Node function, invoke merge and push. 选项2:使用Node函数而不是OGM(下面的注释代码),调用merge和push。

I have done with above mentioned options, but it didn't work for me. 我已经完成了上面提到的选项,但是对我来说不起作用。 Python version 3.5.2 Python版本3.5.2

Code: 码:

try:  
tx = gdb.begin()   ##gdb is Graph object 
for x in moviedict.keys():
 m1 = Movie()
 m1.title = moviedict[x]['title']
 tx.merge(m1)
 m1.year = moviedict[x]['year']
 tx.graph.push(m1)       
tx.commit()
"""Option2 for x in moviedict.keys():
   m1 = Node('Movie',title=moviedict[x]['title'])
   gdb.merge(m1)
   m1['year'] = moviedict[x]['year']
   gdb.push(m1)
 """

Can anyone help me on this issue? 有人可以帮我解决这个问题吗?
Your help is much appreciated. 非常感谢您的帮助。
Best Regards. 最好的祝福。

I didn't use dictionaries, because I wanted the example to be both short and runnable 我不使用字典,因为我希望示例既简短又可运行

    import py2neo
    import py2neo.ogm

    from py2neo import Graph
    from py2neo.ogm import GraphObject, Property

    class Movie(GraphObject):
        __primarykey__ = "title"

        title = Property()
        released = Property()

    def authenticateAndConnect():
        py2neo.authenticate('localhost:7474', 'user', 'password')
        return Graph('http://localhost:7474/default.graphdb/data/')     

    def foo():
        graph = authenticateAndConnect()
        movie = Movie.select(graph).where("_.title = 'The Matrix Reloaded'").first()
        movie.released = 2017
        graph.push(movie)

    if __name__ == '__main__':
        foo()

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

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