Delete all nodes and relationships in neo4j 1.8

后端 未结 7 1827
孤独总比滥情好
孤独总比滥情好 2021-01-30 05:10

I know this question is asked by many people already
for my research, here\'s some questions asked before

  1. How to delete all relationships in neo4j graph?
相关标签:
7条回答
  • 2021-01-30 05:18

    It will do the trick..

    Match (n)-[r]-()
    Delete n,r;
    
    0 讨论(0)
  • 2021-01-30 05:23

    if the name of node is for example : abcd then below query will work :

    MATCH (n:abcd)
    DETACH DELETE n
    

    This will only delete the node with label "abcd" and all its relation-ships.

    0 讨论(0)
  • 2021-01-30 05:30

    As of 2.3.0 and up to 3.3.0

    MATCH (n)
    DETACH DELETE n
    

    Docs

    Pre 2.3.0

    MATCH (n)
    OPTIONAL MATCH (n)-[r]-()
    DELETE n,r
    

    Docs

    0 讨论(0)
  • 2021-01-30 05:36

    you are probably doing it correct, only the dashboard shows just the higher ID taken, and thus the number of "active" nodes, relationships, although there are none. it is just informative.

    to be sure you have an empty graph, run this command:

    START n=node(*) return count(n);
    START r=rel(*) return count(r);
    

    if both give you 0, your deletion was succesfull.

    0 讨论(0)
  • 2021-01-30 05:36

    Neo4j cannot delete nodes that have a relation. You have to delete the relations before you can delete the nodes.

    But, it is simple way to delete "ALL" nodes and "ALL" relationships with a simple chyper. This is the code:

    MATCH (n) DETACH DELETE n

    --> DETACH DELETE will remove all of the nodes and relations by Match

    0 讨论(0)
  • 2021-01-30 05:38

    for a big database you should either remove the database from the disk (after you stop the engine first I guess) or use in Cypher something like:

    MATCH (n)
    OPTIONAL MATCH (n)-[r]-()
    WITH n,r LIMIT 50000
    DELETE n,r
    RETURN count(n) as deletedNodesCount
    

    see https://zoomicon.wordpress.com/2015/04/18/howto-delete-all-nodes-and-relationships-from-neo4j-graph-database/ for some more info I've gathered on this from various answers

    0 讨论(0)
提交回复
热议问题