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 創(chuàng)建節(jié)點(diǎn)
create(stu:Student:Player{id:1,name:'yyk',class:132})
生成一個stu節(jié)點(diǎn),節(jié)點(diǎn)標(biāo)簽是Student和Player眠寿,節(jié)點(diǎn)擁有id,name夭坪,class三個屬性遮怜,屬性值中的字符串用' ';
create(節(jié)點(diǎn)名稱:節(jié)點(diǎn)標(biāo)簽{屬性名:屬性值,屬性名:屬性值...})
merge 在節(jié)點(diǎn)不存在時創(chuàng)建曙聂,存在時無操作;
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不能單獨(dú)使用鞠鲜。
節(jié)點(diǎn)關(guān)系
為了方便測試宁脊,先創(chuàng)建一個Teacher標(biāo)簽的節(jié)點(diǎn)
create(tea:Teacher{id:1,name:'ljy'})
使用已有節(jié)點(diǎn)創(chuàng)建關(guān)系:
match (s:Student),(t:Teacher) create(t)-[r:TEACH{startTime:'2018-06-01'} ]->(s)
創(chuàng)建了一個TEACH關(guān)系,開始時間是2018-06-01
match (s:Student),(t:Teacher) create(t)<-[r:STUDY{startTime:'2018-06-01'} ]-(s)
創(chuàng)建了一個STUDY關(guān)系,開始時間是2018-06-01
使用新節(jié)點(diǎn)創(chuàng)建關(guān)系
create (t:Teacher{name:'ljy'})-[r:TEACH{startTime:'2018-06-01'} ]->(s:Student{name:'yyk'})
remove
刪除節(jié)點(diǎn)的屬性
match(t:Teacher) remove t.name
set
增加/修改節(jié)點(diǎn)屬性
match(t:Teacher) set t.name='yyy' return t
為已存在的節(jié)點(diǎn)添加標(biāo)簽
match(t:Teacher) set t:Father return t
delete
刪除節(jié)點(diǎn)/關(guān)系
match(t:Teacher) delete t
match(s:Student)-[r]-(t:Teacher) delete r,s,t
delete節(jié)點(diǎn)時贤姆,如果節(jié)點(diǎn)之間還有關(guān)系會報(bào)錯
match(t:Teacher) detach delete t 直接將節(jié)點(diǎn)和關(guān)系一起刪除
MATCH (n)
OPTIONAL MATCH (n)-[r]-()
DELETE n,r
order by 排序
match(s:Student) return s order by s.id desc,s.name
union 合并查詢結(jié)果
match(t:Teacher) return t.name
union
match(s:Student) return s.name
limit 限制返回值的個數(shù)榆苞,與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
返回第三行級以后的數(shù)據(jù)
in & null
match(s:Student) where s.id in[1,2] and s.name is not null return s
各關(guān)鍵詞順序
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的節(jié)點(diǎn)
同一個模式中,同一個關(guān)系不會出現(xiàn)兩次
關(guān)系: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延伸匹配關(guān)系,會返回c和a