neo4j基本語法

2021-08-20 23:09:12 字數 2693 閱讀 2742

./bin/neo4j start 啟動專案

瀏覽器開啟http://ip:7474

本地瀏覽器無法訪問遠端的neo4j時,修改neo4j專案conf/neo4j.conf檔案

將紅框處的注釋去掉即可

輸入使用者名稱和密碼(都是neo4j),第一次登入會要求重新設定密碼,進入如下介面

本地瀏覽器無法遠端登入neo4j時

修改neo4j.conf檔案,將紅框處的注釋去掉

cql:

create 建立節點

create(stu:student:player)

生成乙個stu節點,節點標籤是student和player,節點擁有id,name,class三個屬性,屬性值中的字串用' ';

create(節點名稱:節點標籤)

可以create沒有屬性的節點。

create總是建立節點

merge在節點不存在時建立,存在時無操作;

match & return & where

match(stu:student) return (stu)

match(stu:student) return (stu.name)

match(stu:student) where stu.id=1 return (stu)

match.return不能單獨使用。

節點關係

create(tea:teacher)

為了方便測試,先建立乙個teacher標籤的節點

使用已有節點建立關係:

match (s:student),(t:teacher) create (t)-[r:teach ]->(s)

建立了乙個teach關係,開始時間是2018-06-01

match (s:student),(t:teacher) create (t)

建立了乙個study關係,開始時間是2018-06-01

使用新節點建立關係

create (t:teacher)-[r:teach ]->(s:student)

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 直接將節點和關係一起刪除

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)-[:friends]-(b)-[:friends]-(ff)或者

match(a:student)-[:friends]-(b),(b)-[:friends]-(ff) return ff

只返回 c,並不會返回a自己。

match(a:student)-[:friends]-(b) match(b)-[:friends]-(ff) return ff

通過多個match延伸匹配關係,會返回c和a

neo4j的基礎語法

1 建立乙個節點creat variable label 舉例 create n file 注意 我這裡用的單引號,雙引號可能會報錯,看版本 大小寫無所謂 merge建立 2 建立多個節點create variable label variable label variable label 3 建立...

Neo4j 基本操作總結

1.建立節點 create b album 2.建立多個節點 create a album b album 3.建立關係 match a artist b album where a.name 筷子兄弟 and b.name 猛龍過江 create a r released b return r1....

Neo4j學習(2) Win系統安裝Neo4j

neo4j 是目前最流行的圖形資料庫,支援完整的事務,在屬性圖中,圖是由頂點 vertex 邊 edge 和屬性 property 組成的,頂點和邊都可以設定屬性,頂點也稱作節點,邊也稱作關係,每個節點和關係都可以由乙個或多個屬性。neo4j建立的圖是用頂點和邊構建乙個有向圖,其查詢語言cypher...