![](/img/trans.png)
[英]How to use graph.merge() py2neo v3 to replace graph.merge_one() in Nicole White's blog app
[英]py2neo graph.merge() behaves differently from Cypher MERGE?
因此,對於空數據庫MERGE (N1:A {name:"A"})-[:r]->(N2:B {name:"B"})
將創建兩個節點N1
和N2
,其邊緣為r
他們。 但是下面的python代碼沒有這樣做......但為什么呢? 不應該嗎?
from py2neo import Graph, authenticate, rel, Node
graph = Graph()
# set up authentication parameters
authenticate("localhost:7474", <user>, <password>)
# clear the data base
graph.delete_all()
graph.merge(rel(Node("A" , name="A"), "r", Node("B" , name="B")))
運行該腳本會導致數據庫仍為空。 為什么這樣,如何在不使用graph.cypher.execute("MERGE ...")
情況下從py2neo獲取Cypher合並行為?
在Py2neo中, graph.merge
通過label和(可選)屬性匹配或創建單個節點,您希望在整個模式(節點,關系,其他節點)上進行MERGE。
您在Cypher MERGE
語句中使用的模式似乎在Cypher之外的Py2neo中不受支持。
這是一個關於如何合並兩個節點的關系的示例。
from py2neo import Graph, authenticate, Relationship, Node
server = "localhost:7474"
# set up authentication parameters
authenticate(server, <user>, <password>)
graph = Graph("{0}/db/data".format(server))
# merge nodes and relationship
node1 = Node("A", name="A")
node2 = Node("B", name="B")
node1_vs_node2 = Relationship(node1, "r", node2)
graph.merge(node1_vs_node2)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.