Clear Neo4j embedded database

With the new version of Spring Data Neo4j, I cannot use Neo4jHelper.cleanDb (db);

So what is the most efficient way to completely clean up the Embedded Neo4j database in my application?

I used 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 do I clean / delete the database correctly?

UPDATED

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

I am using Spring Data Neo4j and based on a custom request, I want to clear / delete an existing database and recreate it with new data. How do I start a new embedded database after the suggested shutdown method call?

USING:

In a production application, I have configured an 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-populated this database with 1,000,000 nodes. Upon user request, I need to clear this database and populate it with new data. How to properly and quickly clean up an existing database?

Is it possible to call the Neo4j database API to create a node after, database.shutdown()

or do I need to initialize a new database before that?

+1


source to share


1 answer


See another answer to the related question. Inside java, you can close the embedded database using the method GraphDatabaseService#shutdown()

.

From there there are a bunch of different ways to delete the base directory, see this other answer .



So the general answer could be the same:

  • Shutting down the database using the neo4j API
  • Delete database contents from disk
+2


source







All Articles