Recently, the company wants to make a function of knowledge graph, including nodes and relations. Actually, this is a graph in terms of data structure, and we need a database that supports graph structure.
So let’s look at the last one
Command usage of Neo4j
Nodes:
To query all nodes, run MATCH (n) RETURN n
Run the MATCH (n) detach delete n command to delete all nodes
Query nodes based on their IDS: MATCH (n) WHERE ID (n)=251 RETURN n
MATCH (n) WHERE id(n)<>5 and n.name =~ ‘.* Ann.*’ RETURN n
Add node: CREATE (n: writer {name:’ lu Xun ‘}) RETURN n;
Detach delete n Detach delete n Detach delete n Detach delete n Detach delete n detach delete n
Match (b) where ID (b)= 9 Set B: writer, B.name = ‘Kevinnn’ return b
Relationship:
MATCH (c: writer) WITH C OPTIONAL MATCH (c)-[r]-() RETURN c, r
Match (a),(b) where id(a)=9 and id(b)=5 merge (a) -[:test] -> (b)
Delete a relationship based on the ID: match(a)-[r]-(b) where ID (r)=1103 delete r
Find all relationships starting from that ID based on that ID
MATCH (c)-[r]->(d) where id(c) = 5 RETURN r
Delete all relationships starting with c:
MATCH (c)-[r]->(d) where id(c) = 9 delete r