当前位置:   article > 正文

neo4j——电影实战案例——创建节点及关系_neo4j如何建立结点和建立关系

neo4j如何建立结点和建立关系

查看所有图数据

match (n) return n

删除所有图数据

match(n) detach delete n

当时我看书以及找教程,大部分教程和书里的步骤一样,如下图(引用某教程),它是分开创建节点和关系的。

先创建节点

  1. CREATE (TheMatrix:Movie {title:'The Matrix', released:1999, tagline:'Welcome to the Real World'})
  2. CREATE (Keanu:Person {name:'Keanu Reeves', born:1964})
  3. CREATE (Carrie:Person {name:'Carrie-Anne Moss', born:1967})
  4. CREATE (Laurence:Person {name:'Laurence Fishburne', born:1961})
  5. CREATE (Hugo:Person {name:'Hugo Weaving', born:1960})
  6. CREATE (LillyW:Person {name:'Lilly Wachowski', born:1967})
  7. CREATE (LanaW:Person {name:'Lana Wachowski', born:1965})
  8. CREATE (JoelS:Person {name:'Joel Silver', born:1952})

查看所有图数据的结果:

再创建关系

  1. CREATE
  2. (Keanu)-[:ACTED_IN {roles:['Neo']}]->(TheMatrix),
  3. (Carrie)-[:ACTED_IN {roles:['Trinity']}]->(TheMatrix),
  4. (Laurence)-[:ACTED_IN {roles:['Morpheus']}]->(TheMatrix),
  5. (Hugo)-[:ACTED_IN {roles:['Agent Smith']}]->(TheMatrix),
  6. (LillyW)-[:DIRECTED]->(TheMatrix),
  7. (LanaW)-[:DIRECTED]->(TheMatrix),
  8. (JoelS)-[:PRODUCED]->(TheMatrix)

 

再查看所有图数据的结果,发现什么??发现新世界,为什么出现了新的空白关系????


 

正确的步骤:

电影实战案例的部分语句

  1. CREATE (TheMatrix:Movie {title:'The Matrix', released:1999, tagline:'Welcome to the Real World'})
  2. CREATE (Keanu:Person {name:'Keanu Reeves', born:1964})
  3. CREATE (Carrie:Person {name:'Carrie-Anne Moss', born:1967})
  4. CREATE (Laurence:Person {name:'Laurence Fishburne', born:1961})
  5. CREATE (Hugo:Person {name:'Hugo Weaving', born:1960})
  6. CREATE (LillyW:Person {name:'Lilly Wachowski', born:1967})
  7. CREATE (LanaW:Person {name:'Lana Wachowski', born:1965})
  8. CREATE (JoelS:Person {name:'Joel Silver', born:1952})
  9. CREATE
  10. (Keanu)-[:ACTED_IN {roles:['Neo']}]->(TheMatrix),
  11. (Carrie)-[:ACTED_IN {roles:['Trinity']}]->(TheMatrix),
  12. (Laurence)-[:ACTED_IN {roles:['Morpheus']}]->(TheMatrix),
  13. (Hugo)-[:ACTED_IN {roles:['Agent Smith']}]->(TheMatrix),
  14. (LillyW)-[:DIRECTED]->(TheMatrix),
  15. (LanaW)-[:DIRECTED]->(TheMatrix),
  16. (JoelS)-[:PRODUCED]->(TheMatrix)

其实同时创建节点和关系,就会得到想要的图数据了

小白,勿喷!!!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/369772
推荐阅读
相关标签
  

闽ICP备14008679号