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 創(chuàng)建節(jié)點(diǎn)
create(stu:Student:Player{id:1,name:'yyk',class:132})
生成一個(gè)stu節(jié)點(diǎn),節(jié)點(diǎn)標(biāo)簽是Student和Player,節(jié)點(diǎn)擁有id,name,class三個(gè)屬性,屬性值中的字符串用' ';
create(節(jié)點(diǎn)名稱:節(jié)點(diǎn)標(biāo)簽{屬性名:屬性值,屬性名:屬性值...})

merge 在節(jié)點(diǎn)不存在時(shí)創(chuàng)建,存在時(shí)無操作;

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)建一個(gè)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)建了一個(gè)TEACH關(guān)系,開始時(shí)間是2018-06-01

match (s:Student),(t:Teacher) create(t)<-[r:STUDY{startTime:'2018-06-01'} ]-(s)
創(chuàng)建了一個(gè)STUDY關(guān)系,開始時(shí)間是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)時(shí),如果節(jié)點(diǎn)之間還有關(guān)系會報(bào)錯(cuò)
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 限制返回值的個(gè)數(shù),與order by一起用時(shí)反正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)

同一個(gè)模式中,同一個(gè)關(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
通過多個(gè)match延伸匹配關(guān)系,會返回c和a

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • ORACLE自學(xué)教程 --create tabletestone ( id number, --序號usernam...
    落葉寂聊閱讀 1,257評論 0 0
  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,872評論 0 10
  • neo4j使用使用Cypher查詢圖形數(shù)據(jù),Cypher是描述性的圖形查詢語言,語法簡單,功能強(qiáng)大。 和SQL很相...
    8a590e918db0閱讀 4,578評論 0 0
  • 一. Java基礎(chǔ)部分.................................................
    wy_sure閱讀 4,039評論 0 11
  • Cypher 是 借鑒了sql語句的 Neo4j 數(shù)據(jù)庫操作語句 示例:查找john和john朋友的朋友 示例二:...
    陸_志東閱讀 17,828評論 1 16

友情鏈接更多精彩內(nèi)容