How to reset database and node ID increment?

2,768 views
Skip to first unread message

Robert Crowe

unread,
Dec 20, 2012, 7:55:38 PM12/20/12
to ne...@googlegroups.com
I'm trying to reset my database so that I get node(0) and new node IDs start counting from 1.  Basically equivalent to truncating a table in SQL.  I've tried the neo4j-clean-remote-db-addon and from a shell running locally on my server I did:

curl -X DELETE http://localhost:7474/db/data/cleandb/secret-key

but although it returns a response of "Node[0]" it doesn't seem to do what I need.  The Dashboard on the webadmin tool still shows a lot of nodes and relationships, and when I create a new node it starts counting from where the increment was before.  When I do:

start n=node(*) return n;

it shows all the nodes.  I'm using v1.8 of both Neo4j and the plugin.  It seems like there must be a standard way of doing this that everyone is using, but I can't seem to find it.  How do you do it?

thanks in advance,

Robert

Michael Hunger

unread,
Dec 20, 2012, 8:28:43 PM12/20/12
to ne...@googlegroups.com
Robert,

what did you add to your neo4j-server.properties for the plugin?

The shown high-ID's in the webadmin won't change, but the cypher query shouldn't return anything.

You can also use cypher to delete all nodes:

START n=node(*)
MATCH n-[r?]->()
DELETE r
WHERE ID(n) <> 0
DELETE n

Michael

--
 
 

Robert Crowe

unread,
Dec 20, 2012, 9:03:10 PM12/20/12
to ne...@googlegroups.com
I added this to the neo4j-server.properties and did a restart:

org.neo4j.server.thirdparty_jaxrs_classes=org.neo4j.server.extension.test.delete=/db/data/cleandb
org
.neo4j.server.thirdparty.delete.key=secret-key

I think that the problem could be that I deleted node(0), because to try to clear I did:

start n=node(*) match n-[r?]->() delete r, n

and I notice that you're avoiding deleting node(0) in your query.  I suppose I could replace the data set file, but it really seems like it needs something like truncate.

thanks,

Robert

Robert Crowe

unread,
Dec 21, 2012, 3:02:59 PM12/21/12
to ne...@googlegroups.com
The easiest way that I've found is to create a new dataset, and it's very easy to do.  I edited conf/neo4j-server.properties and changed location to point to a directory that didn't exist, and then restarted the server:

org.neo4j.server.database.location=data/graph_clean.db

I called mine "graph_clean".  On restart Neo4j creates a clean dataset if it doesn't find the one set in the properties.

Happy holidays,

Robert

Michael Hunger

unread,
Dec 21, 2012, 3:20:38 PM12/21/12
to ne...@googlegroups.com
Right,

Both the clean plugin and the cypher cleanup are just ways of getting rid of the data without restarting the server, e.g. during integration tests.

It is even easier, just shutdown the server, delete the configured directory and start again. No need to change the config entry.

Michael

--
 
 

Reply all
Reply to author
Forward
0 new messages