创建文件夹:mkdir /opt/neo4j
进入neo4j文件夹:cd /opt/neo4j
创建docker-compose.yml文件:vim docker-compose.yml
version: '3.2'
services:
neo4j:
user: 'root'
container_name: neo4j
image: neo4j:4.3.4-community
networks:
- neo4j
ports:
- '7474:7474'
- '7687:7687'
restart: always
volumes:
- ./data:/var/lib/neo4j/data
- ./logs:/var/lib/neo4j/logs
- /tmp:/tmp
deploy:
resources:
limits:
cpus: '1.00'
memory: 1024M
logging:
driver: "json-file"
options:
max-size: "50M"
max-file: "10"
environment:
- NEO4J_AUTH=neo4j/123456
networks:
neo4j:
进入neo4j文件夹执行命令:docker-compose up -d
查看启动状态:docker ps -a
启动成功后打开浏览器访问:http://192.168.80.230:7474/
username: neo4j
password: 123456
2.1.1.创建没有属性的节点:CREATE (a:User)
2.1.2.创建具有属性的节点:
CREATE (a:User { id:1,name:"张三",address:"Hyderabad" })
2.2.1.查询user标签下的所有内容
MATCH (a:User) return a
2.2.2.查询user标签下 id=1,name="张三"的节点
MATCH (p:User {id:1,name:"张三"} ) RETURN p
MATCH (p:User) where p.id = 1 and p.name = "张三" RETURN p
2.2.3.查询2个节点之间的关系
MATCH (cc:User)-[r]-(c:Sheng)RETURN r
CREATE (a:User)-[r1:位于]->(b:Sheng)
这里a和User是节点名称和节点标签名称“From Node”
b和Sheng是“To Node”的节点名称和节点标签名称
r1是关系名称
位于是一个关系标签名称
MATCH (m:man { id: 1 }) MATCH (d:Dept { deptno: 10 }) MERGE (m)-[r:相似]->(d) ON CREATE SET r.created = timestamp() RETURN r
CREATE (p1:Profile1)-[r1:LIKES]->(p2:Profile2)
MATCH (cust:Book),(cc:man) WHERE cust.id = 122 AND cc.id= 3 CREATE (cust)-[r:人看书]->(cc) RETURN r
Neo4j CQL DELETE和REMOVE命令之间的主要区别 :
MATCH (e: User) DELETE e
MATCH (cc: User)-[rel]-(c:Sheng) DELETE cc,c,rel
DELETE
先创建Book 节点
CREATE (book:Book {id:122,title:"Neo4j Tutorial",pages:340,price:250})
查询Book节点属性值,结果如下
MATCH (book : Book) RETURN book
删除price属性后查询结果如下,
MATCH (book { id:122 }) REMOVE book.price RETURN book
MATCH (n:GMYJZJ), (m:QHS)
WHERE n.ID = '420104198110060430' AND m.ID = '420000'
MATCH p = (n)-[*..3]-(m)
RETURN p
ORDER BY length(p) ASC
SKIP 0 LIMIT 10
MATCH (z:GMSGXX) ,(gmyjzj:GMYJZJ) ,(qhss:QHSS)
MATCH p1=shortestPath((z)-[*]-(gmyjzj))
MATCH p2=shortestPath((z)-[*]-(qhss))
where gmyjzj.ID = "420104198110060430" and qhss.ID = "420100"
return p1,length(p1) , p2,length(p2) limit 5;
MATCH (c:User {ID: '123456'})-[]-(related)
RETURN c, related