更新 属性 与 py2neo neo4j 的关系

Update property relation with py2neo neo4j

我正在尝试检查两个节点之间是否存在关系,但出现此错误:

raise TypeError("Nodes for relationship match end points must be bound") TypeError: Nodes for relationship match end points must be bound

在我的代码下方:

graph = Graph(user='neo4j')

src = Node(src_type, internal_id=int(src_id))
dst = Node(dst_type, internal_id=int(dst_id))

src_voted_dst = Relationship(src, "VOTED", dst)

for elem in graph.match(start_node=src, rel_type="VOTED", end_node=dst, bidirectional=True):
    elem.properties["vote"] = elem.properties["vote"] + 1
    elem.push()
    break
else:
    src_voted_dst.properties["vote"] = 1
    graph.merge(src_voted_dst)

代码中:

src = Node(src_type, internal_id=int(src_id))
dst = Node(dst_type, internal_id=int(dst_id))

src和dst是在本地创建的,但没有绑定到数据库中的这些节点。 使用 merge:

将本地节点绑定到数据库
db_src = graph.merge(src)
db_dst = graph.merge(dst)

然后匹配应该起作用:

for elem in graph.match(db_src, "VOTED", db_dst)

(注意elem.properties["vote"]不行,应该有东西linkelem.start_node()["vote"]或者elem.end_node()["vote"])