2
votes

We are doing some experiments with Neo4j and for this we want to load and reload data to Neo4j using Cypher. We would like to fire off a Cypher script (.cql) of this structure:

// Remove existing nodes/rels
START r=rel(*)
DELETE r;


START n=node(*)
DELETE n;

// Load new data
CREATE ()....

We really can't find a way to do this in a good way. Should we use the console, http or the data browser?

Thanks for any input.

regs

2

2 Answers

2
votes

I'd use neo4j-shell for this:

bin/neo4j-shell < myScript.cql

For only deleting all contents of your DB, you could also do

bin/neo4j stop; rm -rf data/graph.db; bin/neo4j start
0
votes

You should encapsulate your statements within transaction blocks. begin ... commit

How much data do you delete?

If it is too much, you might want to page it, otherwise the transaction state gets too big for your memory, probably experiment how much you can delete in one go. E.g.

BEGIN
START r=rel(*)
WITH r
LIMIT 40000
DELETE r;
COMMIT

and repeat as needed.

Make sure your neo4j-shell has enough RAM (if you don't connect the shell to a running server then the execution runs in the server). Edit bin/neo4j-shell and set

EXTRA_JVM_ARGUMENTS="-Xmx4G"