database 如何重置/清除/删除neo4j数据库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23310114/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 09:14:34  来源:igfitidea点击:

How to reset / clear / delete neo4j database?

databaseneo4jcypher

提问by Somnath Muluk

We can delete all nodes and relationships by following query.

我们可以通过以下查询删除所有节点和关系。

MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE n,r

But newly created node get internal id as ({last node internal id} + 1) . It doesn't reset to zero.

但是新创建的节点将内部 id 设为 ({last node internal id} + 1) 。它不会重置为零。

How can we reset neo4j database such as newly created node will get id as 0?

我们如何重置neo4j数据库,例如新创建的节点将获得id为0?

From 2.3, we can delete all nodes with relationships,

从2.3开始,我们可以删除所有有关系的节点,

MATCH (n)
DETACH DELETE n

回答by Stefan Armbruster

Shut down your Neo4j server, do a rm -rf data/graph.dband start up the server again. This procedure completely wipes your data, so handle with care.

关闭您的 Neo4j 服务器,执行 arm -rf data/graph.db并再次启动服务器。此过程会完全擦除您的数据,因此请小心处理。

回答by Rajitha Fernando

run both commands.

运行这两个命令。

match (a) -[r] -> () delete a, r

above command will delete all nodes with relationships. then run ,

上面的命令将删除所有有关系的节点。然后运行,

match (a) delete a

and it will delete nodes that have no relationships.

它将删除没有关系的节点。

回答by Jordan Morris

If you are using it on a docker container, you can do

如果您在 docker 容器上使用它,则可以执行

docker-compose rm -f -s -v myNeo4jService

docker-compose rm -f -s -v myNeo4jService

回答by makiko_fly

Since neo4j only runs current database specified in the conf file, an easy way to start a new and clean db is to change the current database in the neo4j.conf file and then restart neo4j server.

由于neo4j 只运行conf 文件中指定的当前数据库,因此启动一个新的干净数据库的简单方法是更改​​neo4j.conf 文件中的当前数据库,然后重新启动neo4j 服务器。

dbms.active_database=graph.db --> dbms.active_database=graph2.db

Some might argue that the database name is changed. But as of this writing [2018-12], neo4j doesn't support multiple database instances. There is no need for us to differentiate between databases, thus the name of the database is not used in our code.

有些人可能会争辩说数据库名称已更改。但是在撰写本文时 [2018-12],neo4j 不支持多个数据库实例。我们不需要区分数据库,因此我们的代码中不使用数据库的名称。