Delete several nodes in Neo4j

亡梦爱人 提交于 2019-12-24 14:42:55

问题


I have an array of multiple IDs of nodes to delete. Every Cypher example I can find either deletes one node or all nodes. How would one delete nodes that match an array of IDs, in a single query?

Something like this... (pseudocode):

MATCH (n:Node) WHERE (n.id in ['id_a', 'id_b']) DELETE n;

回答1:


You can use the IN list operator:

If id is a property:

WITH [1,2,3,4] AS ids
MATCH (n) WHERE n.id IN ids
DETACH DELETE n;

If by id you mean the internal node id:

WITH [1,2,3,4] AS ids
MATCH (n) WHERE id(n) IN ids
DETACH DELETE n;


来源:https://stackoverflow.com/questions/48121728/delete-several-nodes-in-neo4j

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