Neo4j

mvn clean install -Dmaven.test.skip -Dpmd.skip

--mongoDB 添加唯一索引
db.t_relation_ref.ensureIndex({business_start_id: 1, relation_code: 1, business_end_id:1, tenant_id:1}, {unique: true});
--neo4j 添加唯一性
create constraint on (s:Node) assert s.business_id is unique

CQL:
create 创建节点
create(stu:Student:Player{id:1,name:'yyk',class:132})
生成一个stu节点,节点标签是Student和Player,节点拥有id,name,class三个属性,属性值中的字符串用' ';
create(节点名称:节点标签{属性名:属性值,属性名:属性值...})

merge 在节点不存在时创建,存在时无操作;

match & return & where
match(stu:Student) return (stu)
match(stu:Student{id:1}) return (stu.name)
match(stu:Student) where stu.id=1 return (stu)
match.return不能单独使用。

节点关系
为了方便测试,先创建一个Teacher标签的节点
create(tea:Teacher{id:1,name:'ljy'})

使用已有节点创建关系:
match (s:Student),(t:Teacher) create(t)-[r:TEACH{startTime:'2018-06-01'} ]->(s)
创建了一个TEACH关系,开始时间是2018-06-01

match (s:Student),(t:Teacher) create(t)<-[r:STUDY{startTime:'2018-06-01'} ]-(s)
创建了一个STUDY关系,开始时间是2018-06-01

使用新节点创建关系
create (t:Teacher{name:'ljy'})-[r:TEACH{startTime:'2018-06-01'} ]->(s:Student{name:'yyk'})

remove
删除节点的属性
match(t:Teacher) remove t.name

set
增加/修改节点属性
match(t:Teacher) set t.name='yyy' return t
为已存在的节点添加标签
match(t:Teacher) set t:Father return t

delete
删除节点/关系
match(t:Teacher) delete t
match(s:Student)-[r]-(t:Teacher) delete r,s,t
delete节点时,如果节点之间还有关系会报错
match(t:Teacher) detach delete t 直接将节点和关系一起删除

MATCH (n)
OPTIONAL MATCH (n)-[r]-()
DELETE n,r

order by 排序
match(s:Student) return s order by s.id desc,s.name

union 合并查询结果
match(t:Teacher) return t.name
union
match(s:Student) return s.name

limit 限制返回值的个数,与order by一起用时反正order by后面
match(s:Student) return s order by s.id limit 2

skip 跳过前面几行
match(s:Student) return s order by s.id skip 2

返回第三行级以后的数据
in & null
match(s:Student) where s.id in[1,2] and s.name is not null return s

各关键词顺序
match(s:Student) where s.name='yyk' return s order by s.id skip 1 limit 2

模糊查询
match(s:Student) where s.name=~'.abc.' 查询name包含abc的节点

同一个模式中,同一个关系不会出现两次
关系:a-好友-b-好友-c

查询a的好友的好友==查询b的好友
match(a:Student{name:'a'})-[:friends]-(b)-[:friends]-(ff)或者

match(a:Student{name:'a'})-[:friends]-(b),(b)-[:friends]-(ff) return ff
只返回 c,并不会返回a自己。

match(a:Student{name:'a'})-[:friends]-(b) match(b)-[:friends]-(ff) return ff
通过多个match延伸匹配关系,会返回c和a

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • ORACLE自学教程 --create tabletestone ( id number, --序号usernam...
    落叶寂聊阅读 1,138评论 0 0
  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,452评论 0 10
  • neo4j使用使用Cypher查询图形数据,Cypher是描述性的图形查询语言,语法简单,功能强大。 和SQL很相...
    8a590e918db0阅读 4,361评论 0 0
  • 一. Java基础部分.................................................
    wy_sure阅读 3,839评论 0 11
  • Cypher 是 借鉴了sql语句的 Neo4j 数据库操作语句 示例:查找john和john朋友的朋友 示例二:...
    陆_志东阅读 17,743评论 1 16