一、基本语法
1、新建节点
(1)基本语法:
() 代表节点
示例:
CREATE (u:User {uid:970939424 }) // 节点类型为User,属性值为uid=970939424
CREATE (u:Round {rid:7194842697444819113 }) // 节点类型为Round对局,属性值为rid:7194842697444819113
2、新建关联边
基本语法:
()-[]->() 代表关联边【需先建立节点,再建立关联边】
示例:
match (n:User {uid:970939424 }),(m:User{uid:658505284}),(r:RoundId {rid:7194842697444819113 })
CREATE (n)-[user_game1:user_game_roundid]-> (r)<-[user_game:user_game_roundid]-(m)
CREATE (u)-[user_game:user_game_roundid}]->(r)
sed -i 's/"//g' 000000_0
删除边:
MATCH (u:User {uid: 1042526861} )-[r : user_game_mpuid ]->(i:Mpuid {mp_uid: "501045_936304347_1042526861" } ) delete r
边更新:
MATCH (u:User {uid: 1042526861} )-[r : user_game_mpuid ]->(i:Mpuid {mp_uid: "501045_342594656_1042526861" } ) SET r={ same_round_cnt: 3 ,win_round_cnt: 3 ,lost_round_cnt: 0 ,coin_change_amt: 403 ,feed_cnt: 0 }
3、创建唯一约束:
基于语法:
()-[]->() 代表关联边【需先建约束,再导入节点数据】
示例:
CREATE CONSTRAINT ON (c:User) ASSERT c.uid IS UNIQUE
CREATE CONSTRAINT ON (r:Round) ASSERT r.rid IS UNIQUE
CREATE CONSTRAINT ON (m:Mac) ASSERT m.mac IS UNIQUE
CREATE CONSTRAINT ON (m:IP) ASSERT m.ip IS UNIQUE
CREATE CONSTRAINT ON (c:IDCard) ASSERT c.idcard IS UNIQUE
CREATE CONSTRAINT ON (m:Mpuid) ASSERT m.mp_uid IS UNIQUE
4、创建索引:
基于语法:
CREATE INDEX FOR (m:Movie) ON (m.released)
示例:CREATE INDEX ON :User(uid)
CREATE INDEX ON :Round(rid)
5、查询:
(1)
MATCH (nineties:Movie) WHERE nineties.released >= 1990 AND nineties.released < 2000 RETURN nineties.title
(2)
用户两度关联用户查询,如果节点多 不加limit 不会展示关联
MATCH p = (u:User)-[*2]-(u2:User) WHERE u.uid=171751482 RETURN p limit 10
6、使用可变长度模式找到电影和演员最多4“跳”远离凯文培根
MATCH (bacon:Person {name:"Kevin Bacon"})-[*1..4]-(hollywood)
RETURN DISTINCT hollywood
7、最短路径查询:
Use the built-in shortestPath() algorithm to find the "Bacon Path" to Meg Ryan.
MATCH p=shortestPath(
(bacon:Person {name:"Kevin Bacon"})-[*]-(meg:Person {name:"Meg Ryan"})
)
RETURN p
8、删除点边
MATCH (n) DETACH DELETE n
MATCH (u:User {uid:toInt(line[0]) } )-[r:user_game_mpuid]-(i:Mpuid {mp_uid: line[1]} )
DELETE r
9、查看历史命令:
:history
10、先导入点,再导入边;
11、节点属性更新
:auto USING periodic commit 3000
LOAD CSV FROM "file:///risk_export_20230613/node/attr_usr.csv" AS line fieldterminator ","
MERGE (u:User {uid:toInt(line[0])})
ON MATCH SET u={
uid:toInt(line[0]),
recharge_amt_td:toInt(line[1]),
is_login_mps_anjian_15d:toInt(line[2]),
is_login_mps_emulator1_30d:toInt(line[3])
}
二、边属性标签更新
1、属性标签存在则更新,不存在则创建文章来源:https://www.toymoban.com/news/detail-705513.html
MATCH (u:User {uid: 2025880357} )-[r : user_game_mpuid ]-(i:Mpuid {mp_uid: "501690_2025469353_2025880357" } ) SET r.lost_cnt1=99000文章来源地址https://www.toymoban.com/news/detail-705513.html
到了这里,关于Neo4j 基本语法的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!