Delete all nodes and relationships

Showing 1-9 of 9 messages
Delete all nodes and relationships Johnny Weng Luu 5/17/12 2:58 PM
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
Re: [Neo4j] Delete all nodes and relationships Michael Hunger 5/17/12 3:11 PM
How did it fail?

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

Michael
Re: [Neo4j] Delete all nodes and relationships Johnny Luu 5/17/12 3:29 PM
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
Re: [Neo4j] Delete all nodes and relationships Johnny Luu 5/17/12 3:29 PM
Perhaps the problem is that when "r" is not available but yet I have "r" in DELETE?

Johnny
Re: [Neo4j] Delete all nodes and relationships Michael Hunger 5/17/12 3:34 PM
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
Re: [Neo4j] Delete all nodes and relationships Johnny Luu 5/19/12 4:31 PM
Why <> 0? Is it possible for an ID to be less than 0?

Johnny

Sent from my iPad
Re: [Neo4j] Delete all nodes and relationships Peter Neubauer 5/20/12 12:13 AM

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

Send from mobile.

Re: Delete all nodes and relationships Yabo Gao 7/2/15 11:33 PM
I tried this and it went ok:
START n = node(*)
      MATCH n-[r]-()
      DELETE n, r
 DELETE n
Its really similar to yours.
Re: [Neo4j] Re: Delete all nodes and relationships Michael Hunger 7/2/15 11:37 PM
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.