Delete all nodes and relationships

3,893 views
Skip to first unread message

Johnny Weng Luu

unread,
May 17, 2012, 5:58:12 PM5/17/12
to ne...@googlegroups.com
First of all, thank you so much for introducing mutative Cypher. It totally rocks!!! :D

I usually delete all nodes and relationships with two queries:

All nodes with relationships:

      START n = node(*)
      MATCH n-[r]-()
      DELETE n, r

All nodes without relationships:

      START n = node(*)
      DELETE n

Is there a way to delete all nodes and relationships with just one query?

I thought this one would do it but it failed:

      START n = node(*)
      MATCH n-[r?]-()
      DELETE n, r

Johnny

Michael Hunger

unread,
May 17, 2012, 6:11:52 PM5/17/12
to ne...@googlegroups.com
How did it fail?

It shouldn't at least not in 1.8-SNAPSHOT ?

Michael

Johnny Weng Luu

unread,
May 17, 2012, 6:29:08 PM5/17/12
to ne...@googlegroups.com
It doesn't delete anything and it messes up the db so I can't delete any node afterwards.

I'm using the latest 1.8 Heroku add-on.

Johnny

Johnny Weng Luu

unread,
May 17, 2012, 6:29:55 PM5/17/12
to ne...@googlegroups.com
Perhaps the problem is that when "r" is not available but yet I have "r" in DELETE?

Johnny

Michael Hunger

unread,
May 17, 2012, 6:34:51 PM5/17/12
to ne...@googlegroups.com
You mean it messes up the console?

Heroku uses 1.8.M02 imho.


Does it work for you here http://console.neo4j.org ?

Oh, you might want to exclude the root node (with where ID(n) <> 0)

Michael

Johnny Luu

unread,
May 19, 2012, 7:31:11 PM5/19/12
to ne...@googlegroups.com
Why <> 0? Is it possible for an ID to be less than 0?

Johnny

Sent from my iPad

Peter Neubauer

unread,
May 20, 2012, 3:13:51 AM5/20/12
to ne...@googlegroups.com

No,
It's just that "! =" is already claimed for optional properties...

Send from mobile.

Yabo Gao

unread,
Jul 3, 2015, 2:33:27 AM7/3/15
to ne...@googlegroups.com, johnny....@gmail.com
I tried this and it went ok:
START n = node(*)
      MATCH n-[r]-()
      DELETE n, r
 DELETE n
Its really similar to yours.

Michael Hunger

unread,
Jul 3, 2015, 2:37:26 AM7/3/15
to ne...@googlegroups.com, johnny....@gmail.com
With a reasonable heap size (4-8G) you can delete up to 1M records (nodes and rels in one run)

If you want to delete all I very much recommend to just to delete the data/graph.db directory.

if you have more data to delete out of even more data, you can do something like this:

// find the nodes you want to delete
MATCH (n:Foo) where n.foo = "bar" 
// take the first 10k nodes and their rels (if more than 100 rels / node on average lower this number)
WITH n LIMIT 10000
MATCH (n)-[r]-()
DELETE n,r
RETURN count(*);

run it until the statement returns 0 (zero).


--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

neo4jnovice

unread,
Jul 10, 2015, 7:01:40 PM7/10/15
to ne...@googlegroups.com, johnny....@gmail.com
How can you ensure that you have successfully updated the heap size to 4-8 GB? I updated it on my Java Runtime Environment Settings and also in the neo4j-wrapper.conf file. However, possibly due to my changing internet speed at the apartment, there is no change in speed after I increased the heap size. Also, the metric system claims that 1 GB is 1000 MB. However, in class, we learned that 1 GB is 2^10=1024 MB. Which metric system is preferred in this case? 
Reply all
Reply to author
Forward
0 new messages