您的位置:首页 > 教育 > 锐评 > neo4j docker安装使用,py2neo python包使用

neo4j docker安装使用,py2neo python包使用

2025/5/3 12:59:01 来源:https://blog.csdn.net/weixin_42357472/article/details/139241669  浏览:    关键词:neo4j docker安装使用,py2neo python包使用

参考:https://neo4j.com/docs/operations-manual/current/docker/introduction/

运行:

docker run --publish=7474:7474 --publish=7687:7687 neo4j

在这里插入图片描述

查看:

http://192***ip:7474
username/password 都是 neo4j/neo4j

在这里插入图片描述
在这里插入图片描述

简单案例
在这里插入图片描述
在这里插入图片描述

创建例子:
关系:SAYS
节点:database、message

数学可以存列表,好像字典存不了

// Hello World!
CREATE (database:Database {name:"Neo4j"})-[r:SAYS]->(message:Message {name:"Hello World!",genre: ["Drama", "Fantasy"]}) RETURN database, message, r

在这里插入图片描述
修改节点:

// 首先找到想要更新的 Message 节点
MATCH (m:Message {name:"Hello World!"})// 然后使用 SET 语句添加新的属性
SET m.content = "This is the content of the message."
SET m.timestamp =DateTime()
SET m.author = "John Doe"RETURN m

在这里插入图片描述

py2neo插入

安装:pip install py2neo

使用Node语句:

每个节点关系后都需要graph.create()

from py2neo import Graph, Node, Relationship# 连接到Neo4j数据库
graph = Graph("bolt://192.168**:7687", auth=("neo4j", "neo4j1"))# 创建 Database 节点和 Message 节点
database = Node("Database", name="Neo4j")
graph.create(database)
message = Node("message", name="Hello World!", genre=["Drama", "Fantasy"])
graph.create(database)
# 创建 SAYS 关系
relationship = Relationship(database, "SAYS", message)# 一次性提交节点和关系到数据库
graph.create(relationship)

修改

import datetime# 更新 Message 节点的属性
message["content"] = "This is the content of the message."
message["timestamp"] = datetime.datetime.now().isoformat()
message["author"] = "John Doe"
message["read"] = False
graph.push(message)# 返回更新后的节点
print(message)

使用Cypher预警:

results = graph.run('CREATE (database:Database {name:"Neo4j"})-[r:SAYS]->(message:Message {name:"Hello World!"}) RETURN database, message, r')

在这里插入图片描述

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com