![](/img/trans.png)
[英]How to find node from node properties but without mentioning label in neo4j using py2neo
[英]Neo4j Py2neo not updating node properties
編寫python程序來獲取現有的Neo4j
節點並使用py2neov3 package
更新屬性。
電影節點具有標題和年份屬性。 有一個帶有要添加電影列表的python字典。
我嘗試了以下選項,正在添加電影節點。 但是年份屬性未更新。
選項1:使用Py2neo OGM。 開始交易,創建Movie對象,填充標題,調用合並,填充年份,調用push,最后提交
選項2:使用Node函數而不是OGM(下面的注釋代碼),調用merge和push。
我已經完成了上面提到的選項,但是對我來說不起作用。 Python版本3.5.2
碼:
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)
"""
有人可以幫我解決這個問題嗎?
非常感謝您的幫助。
最好的祝福。
我不使用字典,因為我希望示例既簡短又可運行
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.