[英]Neo4j cypher query for deleting all children nodes and its relationships except one child node
I am trying to delete child nodes except one child node. 我正在尝试删除除一个子节点以外的子节点。
when I execute this Cypher: 当我执行这个Cypher时:
MATCH (n{name:'Java'})-[r]-(c)
return c.name
I am getting possible node names, but I need only longest node name and I have to delete rest of nodes and its relationships. 我正在获得可能的节点名称,但是我只需要最长的节点名称,就必须删除其余的节点及其关系。
This query should work: 此查询应该工作:
MATCH (n{name:'Java'})--(c)
WHERE EXISTS(c.name)
WITH c ORDER BY LENGTH(c.name) DESC
SKIP 1
DETACH DELETE c;
It finds all c
nodes that have a name
property, orders them in descending order by the length of the name
value, skips the c
node with the longest name, and uses DETACH DELETE
to delete the other c
nodes and all their relationships. 它查找所有具有name
属性的c
节点,按name
值的长度降序排列它们,跳过名称最长的c
节点,并使用DETACH DELETE
删除其他c
节点及其所有关系。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.