Neo4j入门(三)删除关系
共 1909字,需浏览 4分钟
·
2021-08-22 16:10
from py2neo import Graph, Node, Relationship
from py2neo import NodeMatcher, RelationshipMatcher
# 连接Neo4j
url = "http://localhost:7474"
username = "neo4j"
password = "12345678"
graph = Graph(url, auth=(username, password))
print("neo4j info: {}".format(str(graph)))
start_node = NodeMatcher(graph).match("Person", name="Alice").first()
end_node = NodeMatcher(graph).match("Person", name="Bob").first()
rel = RelationshipMatcher(graph).match([start_node, end_node], r_type="Knows").first()
print(rel)
graph.delete(rel)
neo4j info: Graph('http://neo4j@localhost:7474')
(Alice)-[:Knows {}]->(Bob)
from py2neo import Graph, Node, Relationship
from py2neo import NodeMatcher, RelationshipMatcher
# 连接Neo4j
url = "http://localhost:7474"
username = "neo4j"
password = "12345678"
graph = Graph(url, auth=(username, password))
print("neo4j info: {}".format(str(graph)))
start_node = NodeMatcher(graph).match("Person", name="Alice").first()
end_node = NodeMatcher(graph).match("Person", name="Bob").first()
rel = RelationshipMatcher(graph).match([start_node, end_node], r_type="Knows").first()
print(rel)
graph.separate(rel)