728x90
01. 기본 문법
Basic return
MATCH (n)
RETURN n
Create a simple node with properties
CREATE (:NodeName {name: "James Dean", age: 24})
Update return with column names
MATCH (n)
RETURN n.name AS Name, n.age AS Age
Delete all element in the database(delete all nodes and edges)
MATCH (n)
DETACH DELETE n
02. 예제 #1
Two nodes and relationship between User id 0 is interested in the item id 0
CREATE (a:Users {userId: 0})
CREATE (b:Items {itemId: 0})
CREATE (a)-[:IS_INTERESTED_IN]->(b)
Check it labels
call db.labels()
Check it relationship
call db.relationshipTypes
03. 예제 #2
Connect nodes
MATCH (a:Users {userId: 0})
CREATE (b:Items {itemId: 1})
CREATE (a)-[:HAS_PURCHASED]->(b)
Create more nodes
CREATE (u2:Users {userId: 2}),
(u3:Users {userId: 3}),
(u4:Users {userId: 4})
Connect nodes
MATCH (a:Users {userId: 0}), (u2:Users {userId: 2})
CREATE (a)-[:HAS_INTRODUCED_THEITEM_TO]->(u2)
WITH a
MATCH (a), (u3:Users {userId: 3})
CREATE (a)-[:HAS_INTRODUCED_THEITEM_TO]->(u3)
WITH a
MATCH (a), (u4:Users {userId: 4})
CREATE (a)-[:HAS_INTRODUCED_THEITEM_TO]->(u4)
Check it
MATCH (n)
RETURN n
Check it relationship
call db.relationshipTypes
Delete all nodes and edge
MATCH (n)
DETACH DELETE n
04. 예제 #3
Merge either matches existing nodes
MERGE (u0:Users {userId: 0})
MERGE (u1:Users {userId: 1})
MERGE (u2:Users {userId: 2})
MERGE (u3:Users {userId: 3})
MERGE (u4:Users {userId: 4})
MERGE (i0:Items {itemId: 0})
MERGE (i1:Items {itemId: 1})
WITH u0, u1, u2, u3, u4, i0, i1
MATCH (a:Users {userId: 0}), (i0:Items {itemId: 0})
MERGE (a)-[:IS_INTERESTED_IN]->(i0)
WITH a, u1, u2, u3, u4, i1
MATCH (a), (i1:Items {itemId: 1})
MERGE (a)-[:HAS_PURCHASED]->(i1)
WITH a, u2, u3, u4
MATCH (a), (u2:Users {userId: 2})
MERGE (a)-[:HAS_INTRODUCED_THEITEM_TO]->(u2)
WITH a, u3, u4
MATCH (a), (u3:Users {userId: 3})
MERGE (a)-[:HAS_INTRODUCED_THEITEM_TO]->(u3)
WITH a, u4
MATCH (a), (u4:Users {userId: 4})
MERGE (a)-[:HAS_INTRODUCED_THEITEM_TO]->(u4)
Check it
MATCH (n)
RETURN n
05. 예제 #4
Update one property
MATCH (n {userId: 0})
SET n.name = "James Dean"
RETURN n
Update all properties
MATCH (n {itemId: 0})
SET n = {name: "Porsche Super Speedster 23F", Engine: "1.5 L Type 528/2 B4"}
RETURN n
Delete edge property
MATCH (n {itemId: 0})
SET n.Engine = NULL
RETURN n
728x90
'Study > Neo4j' 카테고리의 다른 글
[Neo4j] Neo.ClientError.Security.Unauthorized Error 해결하기(Neo4j 비밀번호 바꾸기) (0) | 2024.08.07 |
---|