cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Nodes without labels but have IDs- how do i delete them?

I have inadvertently created nodes without any labels - but they do have IDs how do I delete them?

2 REPLIES 2

You can use the ID() function, such as:

MATCH (n)
WHERE ID(n)= [id to be deleted] //do not need the brackets just using for emphasis
DETACH DELETE n

This will delete the nodes with their respective relationships (if any).

Similarly, if the nodes are "valid", you could add their Labels and properties using their ID as well.

~Alfonso

If you don't have the IDs of the nodes, but you just want to delete any node without labels, then you can use this:

MATCH (n)
WHERE size(labels(n)) = 0
DETACH DELETE n

Depending on how many there are in the graph, and how many relationships they have, you may need to batch this so you don't blow your heap space.