2

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?

Community
  • 1
  • 1
alexanoid
  • 24,051
  • 54
  • 210
  • 410
  • possible duplicate of [How to reset neo4j database?](http://stackoverflow.com/questions/23310114/how-to-reset-neo4j-database) – FrobberOfBits Jul 23 '15 at 21:10

1 Answers1

2

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
FrobberOfBits
  • 17,634
  • 4
  • 52
  • 86
  • Thanks! One more question - if I need to delete/clear database several times on a working application - do I need to perform some additional steps in order to start using new embedded database right after deleting ? – alexanoid Jul 24 '15 at 06:30
  • No; embedded databases are tied to directories on disk. Just create a new database, and it will auto-create whatever directories are necessary. – FrobberOfBits Jul 24 '15 at 12:32
  • You must create a new database before you insert new data. If you try to insert data after shutdown, it will fail. Please mark this question completed and move on - if you have additional questions open new topics. – FrobberOfBits Jul 25 '15 at 01:07