I have inadvertently created nodes without any labels - but they do have IDs how do I delete them?
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.
1 Like