经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 数据库/运维 » neo4j » 查看文章
Neo4j常用的查询
来源:cnblogs  作者:mzyn22  时间:2019/6/28 8:43:45  对本文有异议

一、添加操作

  1. 添加节点:

    create (x:学生{studentId:'1001',age:20}

  2. 添加关系:

    对现有的节点添加关系

      match (x:学生{studentId:1001}),(y:教师{tid:'09'}) create (x)-[jx:课程{name:'高数'}]->(y)

    添加节点并添加关系

      create (x:学生{studentId:1001})-[jx:课程{name:'高数'}]->(y:教师{tid:'09'}) 

二、删除操作

  1. 删除节点:

    match (x:学生{studentId:1001}) delete x

  2. 删除关系:

    match (x:学生{studentId:1001})-[jx:课程{name:'高数'}]->(y:教师{tid:'09'})  delete jx

  3. 删除关系的同时,删除数据:

    match (x:学生{studentId:1001})-[jx:课程{name:'高数'}]->(y:教师{tid:'09'})  delete x,jx,y

三、修改节点

  1. 给节点添加一个新的属性,两种方式:

    match(x:学生{studentId:'1001'}) set x.age=21 return x

    match(x:学生{studentId:'1001'}) set x+={age:21} return x

  2. 给节点添加属性并删除现有属性

    match(x:学生{studentId:'1001'}) set x={age:21,name:'abc'} //注意这里,会将studentId属性删除

  3. 添加新标签:

    match(x:学生{studentId:'1001'}) set x:男生 return x  //添加一个标签

    match(x:学生{studentId:'1001'}) set x:男生:团员 return x  //添加多个标签

四、查询操作

  1. 根据节点属性查找对应节点:

    match(x:Student{studentId:'1001'}) return x

    或者

    match(x:Student) where x.studentId='1001' return x

  2. 根据关系查找节点

    match (x)-[r:教学内容]-(y) where r.课程='语文' return x,r,y

  3. 查询单独的节点,即:与其他任何节点没有任何关系

    match(x) where not (x)-[]-() return x

  4. 查询N层关系的节点:

    match q=(x)-[*5..8]-() return q limit 200 这个为查询5到8层关系的

    match q=(dh)-[r]-(jq)-[rr]-()-[]-()-[]-()-[]-()-[]-()-[]-() return q limit 400

  5. 查询节点关系数个数:

    match(dh:`学生`)-[r]-(jq:`老师`) with dh, count(r) as dhs where dhs > 2 return dh

  6. 查询节点个数:

    match(x) return count(x)

  7. 查询所有的关系类型:

    CALL db.relationshipTypes()

  8. 查询所有的节点标签:

    CALL db.labels()

   9. 查询节点关系种类:

    CALL db.schema()

  暂时先写这么多吧,想起来了再添加

原文链接:http://www.cnblogs.com/mzyn22/p/11098285.html

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号