How to delete / create databases in Neo4j?

Is it possible to create / delete various databases in the Neo4j graph database , as in MySQL? Or at least how to remove all nodes and relationships of an existing graph to get a clean tuning for tests, for example, using shell commands similar to rmrel or rm ?

+86
database sql-delete neo4j nodes relationships
Dec 21 '10 at
source share
12 answers

You can simply delete the entire graph directory with rm -rf , because Neo4j does not store anything outside this:

 rm -rf data/* 

In addition, you can, of course, iterate over all the nodes and delete their relationships and the nodes themselves, but this can be too expensive just for testing ...

+80
Dec 22 '10 at 9:32
source share

an even simpler command to remove all nodes and links:

 MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE n,r 
+80
Jan 21 '14 at 6:32
source share

Creating a new database in Neo4j

Before launching the neo4j community, click the browse button

enter image description here

and select another directory

enter image description here

enter image description here

and click the start button.

enter image description here

New database created in this directory

+44
May 29 '14 at 9:53
source share

From Neo4j 2.3,

We can remove all nodes with relationships ,

 MATCH (n) DETACH DELETE n 

There is currently no way to create multiple databases in Noe4j. You need to make several Neo4j data stores. See link .

+32
Oct 28 '15 at 13:07 on
source share

For anyone who needs a clean graph to run a test suite, https://github.com/jexp/neo4j-clean-remote-db-addon is a great extension to clear db through a REST call. Obviously, however, do not use it in production!

+11
Sep 29 '11 at 17:32
source share

quick and dirty way that works great:

 bin/neo4j stop rm -rf data/ mkdir data bin/neo4j start 
+10
Jul 14 '14 at 20:48
source share

Run your test code on another instance of neo4j.

  • Copy the neo4j directory to a new location. Use this for testing. cd to the new directory.
  • Change the port so you can run your tests and use it at the same time. To change the port, open conf/neo4j-server.properties and set org.neo4j.server.webserver.port to unused.
  • Run the test server during configuration. Make ./neo4j stop and rm -rf data/graph.db if rm -rf data/graph.db .

See neo4j for more details : How to switch the database? and docs .

+6
Mar 20 '13 at 17:06
source share

Is there a Neo4j 2.0.0? is no longer supported. Use the OPTIONAL MATCH instead:

 START n=node(*) OPTIONAL MATCH (n)-[r]-() delete n,r; 
+5
Feb 08 '14 at 3:25
source share

The simplest answer: NO

The best way to get started is

  • go to another empty data folder

or

  • close Neo4j completely
  • delete old data folder
  • restart Neo4j and set the empty folder to the data folder

There is a way to remove all nodes and relationships (as described here )

 MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE n,r 
+5
Jun 11 '15 at
source share

In 2.0.0-M6, you can run the following Cypher script to remove all nodes and relationships:

 start n=node(*) match (n)-[r?]-() delete n,r 
+1
Nov 14 '13 at 10:02
source share

Starting with version 3, I believe that now you can create separate database instances and, therefore, their location is slightly different.

Referring to: https://neo4j.com/developer/guide-import-csv/

. --into retail.db is obviously a target database that should not contain an existing database.

In my Ubuntu field, the location is in:

/var/lib/neo4j/data/databases Here I see only graph.db , which, in my opinion, should be the default.

+1
Apr 25 '17 at 11:50
source share

You can delete your data files, and if you want to go this way, I would recommend deleting only your graph.db, for example. Otherwise, you are going to spoil your authentication information.

0
Oct 07 '15 at 2:57
source share



All Articles