Neo4j入门(三)删除关系
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)