Clear Neo4j Embedded database

北慕城南 提交于 2019-12-10 11:14:23

问题


With a new version of Spring Data Neo4j I can't use Neo4jHelper.cleanDb(db);

So, what is the most effective way to completly clear Embedded Neo4j database in my application?

I have implemented my own util method for this purpose, but this method is slow:

public static void cleanDb(Neo4jTemplate template) {
    template.query("MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE n,r", null);
}

How to properly clear/delete database ?

UPDATED

This is the similar question How to reset / clear / delete neo4j database? but I don't know how to programmatically shutdown Embedded Neo4j and how to start it after deleting.

I use Spring Data Neo4j and based on the user request I'd like to clear/delete existing database and recreate it with a new data. How to start up new embedded database after suggested invocation of shutdown method ?

USE CASE:

On the working application I have configured embedded database:

GraphDatabaseService graphDb = new GraphDatabaseFactory()
                .newEmbeddedDatabaseBuilder(environment.getProperty(NEO4J_EMBEDDED_DATABASE_PATH_PROPERTY))
                .setConfig(GraphDatabaseSettings.node_keys_indexable, "name,description")
                .setConfig(GraphDatabaseSettings.node_auto_indexing, "true")
                .newGraphDatabase();

Also, I pre populate this database with 1000000 nodes. On the user request I need to clear this database and populate it with a new data. How to correctly and quick clear existing database ?

Can I call Neo4j database API for new node creation after database.shutdown() or do I need to initialize new database before it?


回答1:


See the other answer on the related question. Inside of java, you can shut down an embedded database with the GraphDatabaseService#shutdown() method.

From there, there are a pile of different ways you can delete the underlying directory, see this other answer.

So the general answer can still be the same:

  1. Shutdown the database using the neo4j java API
  2. Delete the database contents off of the disk


来源:https://stackoverflow.com/questions/31597809/clear-neo4j-embedded-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!