我们使用NEO4j的CQL语句,可以删除一个节点,也可以删除一个关系
下图表示了假设微博用户张三跟随了李四和王五,而赵六和他们没有关系
CREATE (:User {name: '张三', age: 28})
CREATE (:User {name: '李四', age: 32})
CREATE (:User {name: '王五', age: 45})
CREATE (:User {name: '赵六', age: 16})
MATCH (p1:User{name:'张三'}),(p2:User{name:'李四'})
CREATE (p1)-[:FOLLOW]->(p2)
MATCH (p1:User{name:'张三'}),(p2:User{name:'王五'})
CREATE (p1)-[:FOLLOW]->(p2)
MATCH (u:User {name: '赵六'}) DELETE u
删除前
MATCH (p1)-[r:FOLLOW]-(p2) RETURN *
MATCH (p1 {name: '张三'})-[r:FOLLOW]->(p2{name:'李四'}) DELETE r
删除后
MATCH (p1)-[r:FOLLOW]-(p2) RETURN *
MATCH (n {name: '张三'}) DETACH DELETE n
MATCH (n) DETACH DELETE n