Search code examples
neo4jnosqlcyphergraph-databases

What's the Cypher script to delete a node by ID?


In SQL:

Delete From Person Where ID = 1;

In Cypher, what's the script to delete a node by ID?

(Edited: ID = Neo4j's internal Node ID)


Solution

  • (Answer updated for 2024!)

    Assuming you're referring to Neo4j's internal element id:

    MATCH (p:Person) where elementId(p)=1
    DETACH DELETE p
    

    Assuming you're referring to Neo4j's (legacy) internal id:

    MATCH (p:Person) where ID(p)=1
    DETACH DELETE p
    

    If you're referring to your own property 'id' on the node:

     MATCH (p:Person {id:1})
     DETACH DELETE p