Steven Gall
Steven Gall

Reputation: 113

Neo4j cypher: Deleting a collection of relationships

I think this may be a bug, however, when deleting a collection of relationships the start node is also deleted. I am running neo4j community edition 2.3.3 and have run the following queries in order.

match (u:User)-[]->(p:Pie)-[c:CONSISTS_OF*1]->() where id(u) = 6398 and id(p)= 6436 return p,c Which returns Displaying 3 nodes, 2 relationships. and the graph in the imageDisplaying 3 nodes, 2 relationships.

match (u:User)-[]->(p:Pie)-[c:CONSISTS_OF*1]->() where id(u) = 6398 and id(p)= 6436 FOREACH( q in c | DELETE q) Which results in Deleted 2 relationships, statement executed in 103 ms.

And then what I am finding is instead of the collection of relationships c being deleted, the node p is also deleted…

match (u:User)-[]->(p:Pie)-[c:CONSISTS_OF*1]->() where id(u) = 6398 and id(p)= 6436 return p Which results in (no rows)

I would simply like to delete the collection of relationships. I also feel like this feature is something that makes sense but hasn’t been revisited since late 2013… https://github.com/neo4j/neo4j/issues/1612

EDIT: In an earlier version of the question I had DETACH DELETE instead of DELETE. This was a mistake in the posting of the question. I have since revised it. It should be noted that the reason I think this may be a bug is because both DETACH DELETE and DELETE behave the same in this scenario.

Upvotes: 0

Views: 366

Answers (1)

jjaderberg
jjaderberg

Reputation: 9952

In the MATCH query that you use to check whether the (p:Pie) node exists after deleting the relationships you still include the -[c:CONSISTS_OF*1]-> part of the pattern. That part doesn't match anything, because you deleted those relationships. But then the whole pattern won't match anything either, whether or not the node still exists.

You can use MATCH (p:Pie) WHERE id(p) = 6436 to test that the (p:Pie) node still exists.

Upvotes: 1

Related Questions