CQL 代表密码查询语言。就像 Oracle 数据库有查询语言 SQL,Neo4j 有 CQL 作为查询语言。
CREATE (node_name);
其中(;)是可选的。
CREATE (node_name1),(node_name2)
CREATE (node:label)
CREATE (node:label1:label2:...labeln)
CREATE (node:label1{name:"zhangsan", year:1999, country:"China"})
MATCH (n) RETURN n;
CREATE (node:label1{name:"zhangsan", year:1999, country:"China"}) RETURN node
首先在数据库中创建两个节点Dhawan和Ind,如下:
CREATE (Dhawan:player {name:"Shikar Dhawan", YOB:1985, POB:"Delhi})
CREATE (Ind:Country {name:"India"})
在两节点间建立一个名为 BATSMAN_OF 的关系
CREATE (Dhawan)-[r:BATSMAN_OF]->(Ind)
最后,返回两个节点以查看创建的关系
RETURN Dhawan, Ind
MATCH (a:player), (b:Country) WHERE a.name="Shikar Dhawan" AND b.name = "India" CREATE (a)-[r:BATSMAN_OF]->(b) RETURN a,b
MATCH (a:player), (b:Country) WHERE a.name = "Shikar Dhawan" AND b.name = "India"
CREATE (a)-[r:BATSMAN_OF {Matches:5, Avg:90.75}]->(b) RETURN a,b
CREATE p = (Node1 {properties})-[:Relationship_Type]-> (Node2 {properties})[:Relationship_Type]->(Node3 {properties}) RETURN p
MERGE 命令是 CREATE 命令和 MATCH 命令的组合。
Neo4j CQL MERGE 命令在图中搜索给定模式。如果存在,则返回结果。
如果它在图中不存在,那么它会创建一个新的节点/关系并返回结果。
CREATE (Dhawan:player{name: "Shikar Dhawan", YOB: 1985, POB: "Delhi"})
CREATE (Ind:Country {name: "India"})
CREATE (Dhawan)-[r:BATSMAN_OF]->(Ind)
Neo4j 会验证是否存在具有给定标签的任何节点。如果没有,将创建当前节点。
MERGE (Jadeja:player) RETURN Jadeja
MERGE (Jadeja:player {name: "Ravindra Jadeja", YOB: 1988, POB: "NavagamGhed"}) RETURN Jadeja
MATCH (a:Country), (b:Tournament)
WHERE a.name = "India" AND b.name = "ICC Champions Trophy 2013"
MERGE (a)-[r:WINNERS_OF]->(b)
RETURN a, b
未完待续