刚学会了大致neo4j的常用操作,这里把常用的命令分享给大家!
创建节点
CREATE (emp:Employee)
创建节点和属性
CREATE (dept:Dept { deptno:10,dname:“Accounting”,location:“Hyderabad” })
查询Match语句
match (n) return n
查询Employee标签下 id=123,name="Lokesh"的节点
MATCH (p:Employee {id:123,name:“Lokesh”}) RETURN p
查询Employee标签下name="Lokesh"的节点,使用(where命令)
MATCH (p:Employee) WHERE p.name = “Lokesh” RETURN p
查询关系
MATCH p=(n:Person{name:“成龙”})-[r:饰演
]->() RETURN p LIMIT 25
DELETE 删除
MATCH (e: Employee) DELETE e
Match p=()-[r:Friend]->() Delete p
match ()-[r:BASIC]->() delete r
关系创建
CREATE (p1:Profile1)-[r1:LIKES]->(p2:Profile2)
SET子句 向现有节点或关系添加新属性
MATCH (book:Book) SET book.title = ‘superstar’ RETURN book
REMOVE删除节点
MATCH (book { id:122 }) REMOVE book.price RETURN book
DELETE操作用于删除节点和关联关系。
REMOVE操作用于删除标签和属性。
导入实体
LOAD CSV WITH HEADERS FROM ‘file:///movie.csv’ AS line FIELDTERMINATOR ‘,’
CREATE (:Movie {title: line.title,introduction: line.introduction,rating:line.rating,releasedate:line.releasedate,mid:line.mid})
导入实体
LOAD CSV WITH HEADERS FROM “file:///person.csv” AS line FIELDTERMINATOR ‘,’
CREATE (:Person{name: line.name,pid:line.pid,birth: line.birth,death: line.death,biography: line.biography,birthplace: line.birthplace})
导入实体
LOAD CSV WITH HEADERS FROM ‘file:///genre.csv’ AS line FIELDTERMINATOR ‘,’
CREATE (:Genre {gname: line.gname,gid: line.gid})
导入关系方法:
LOAD CSV WITH HEADERS FROM ‘file:///person_to_movie.csv’ AS line
MATCH (from:Person{pid:line.pid}),(to:Movie{mid:line.mid})
MERGE (from)-[r:饰演]-> (to);
查询2个人一起出演的电影
MATCH p=(n:Person{name:“成龙”})-[r:饰演
]->(m:Movie)<-[k:饰演
]-(cn:Person{name:“洪金宝”}) return p