How to delete multiple nodes in neo4j

[亡魂溺海] 提交于 2019-12-10 16:45:49

问题


How to delete multiple nodes, (NOT ALL) in neo4j?

I have this query
MATCH (n)
where n.name IS NULL
delete n

It returns more than one node, I want to delete all those nodes(All nodes, which are mistakenly created thats why become null).

The error, I am facing is

javax.transaction.HeuristicRollbackException: Failed to commit transaction Transaction(11, owner:"qtp16626756-84")[STATUS_NO_TRANSACTION,Resources=1], transaction rolled back ---> javax.transaction.xa.XAException

CASE 2: What to do in case of NOT NULL (property) but no any relationship is associated within a node or two; means a node which is kind of orhpan, not connected with other node.

I tried to use LIMIT/SKIP but not working.Any help?


回答1:


You need to also delete any relationships connected to those nodes, like so:

match (n)
where n.name IS NULL
optional match (n)-[r]-()
delete n, r

Update for your second case (this deletes only orphans):

match (n)
where NOT (n)--()
  and n.name IS NULL
delete n


来源:https://stackoverflow.com/questions/21022290/how-to-delete-multiple-nodes-in-neo4j

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!