当前位置:   article > 正文

Neo4j入门到精通_neo4j菜鸟教程

neo4j菜鸟教程

一、下载安装

https://pan.baidu.com/s/1hygHS6_W5rqoAc41V30sTQ 提取码:v5z4
  • 1

二、修改配置启动

切换到bin目录,输入neo4j.bat console命令之后
  • 1

三、 增删改查

1、语法说明

括号代表节点、大括号代表对象、中括号代表关系

2、清空数据库

match (n) detach delete n
  • 1

3、添加4个节点

小写student 可以理解为面向对象的实体
大写Student 可以理解为面向对象的类

create(student:Student{
   id:1, name: "李雷"});
create(student:Student{
   id:2, name: "韩梅梅"});
create(teacher:Teacher{
   id:1, name: "仓老师"});
create(school:School{
   id: 1, title: "山东蓝翔"});
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

在这里插入图片描述

4、添加3个关系

match(s:Student{
   id:1}),(t:Teacher{
   id:1}) create (t)-[r:教授]->(s);
match(s:Student{
   id:2}),(t:Teacher{
   id:1}) create (t)-[r:教授]->(s);
match(s:School{
   id:1}),(t:Teacher{
   id:1}) create (t)-[r:就职于]->(s);
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

在这里插入图片描述

5、更新节点 老师改名字了

match(t:Teacher) 
where t.id=1 
set t.name="小泽老师"
  • 1
  • 2
  • 3

6、删除节点 李雷被开除了

match(s:Student{
   id: 1}) 
detach delete s;
  • 1
  • 2
  • 3

7、删除关系 小泽老师去别的班级上课了

match (t:Teacher)-[r:教授]->(s:Student) 
where t.id=1 and s.id=2 
delete r
  • 1
  • 2
  • 3

8、索引操作

查看所有索引 
:schema

创建索引
create index on:Student(name)

删除索引
drop index on:Student(name)

创建唯一索引
create constraint on (s:Teacher) assert s.name is unique

删除唯一索引
drop constraint on (s:Teacher) assert s.name is unique
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

9、修改关系名称

MATCH (p:Person)-[r:投资]->(<
    声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/852771
    推荐阅读
      

    闽ICP备14008679号