Mark
Mark

Reputation: 92440

Unable to load NODE with id

I recently upgraded my Neo4j database to v. 3 (3.0.6). Since then I am having trouble when trying to delete nodes with Cypher. This is a new problem since the upgrade. They Cypher query is:

MATCH (p) WHERE id(p) = 83624 
OPTIONAL MATCH (p)-[r]-(n)
OPTIONAL MATCH (p)-[r2]-(n2)  
WHERE NOT ('Entity' in labels(n2)) 
DELETE r, r2, p, n2

This now results in the error Unable to load NODE with id 83624

The exact query with RETURN instead of DELETE returns the node. I've also tried swapping out DELETE with DETACH DELETE of the nodes, but that gives me the same error.

It looks like this question has been asked before but without a solution. Any idea what is causing this error?

Upvotes: 2

Views: 1994

Answers (1)

InverseFalcon
InverseFalcon

Reputation: 30397

I'm a little confused by this query. Both of your optional matches are identical, in that they will match to any relationship to any node connected to p.

Let me make sure I understand what you're trying to do: Find a node by ID, then delete that node along with any connected node that is not an Entity (as well as the relationships connecting them). Is that right?

If so, this query might work better:

MATCH (p) WHERE id(p) = 83624 
OPTIONAL MATCH (p)--(n)
WHERE NOT n:Entity
DETACH DELETE n
DETACH DELETE p

Detaching a node deletes all relationships connected to that node, and you can only delete a node that has zero relationships.

Also, just to note, it's not a good idea to use the internal ids for uniquely identifying nodes. It's recommended to use your own unique IDs instead, and create unique constraints on that property for that label.

Upvotes: 1

Related Questions