在Neo4j 2.1.6中,我有一些关于某个属性inputID
的非唯一节点。
使用Cypher,如何根据给定属性删除所有重复的节点,只留下唯一身份?
我试过以下......
MATCH (n:Input)
WITH n.inputID, collect(n) AS nodes
WHERE size(nodes) > 1
FOREACH (n in tail(nodes) | DELETE n)
......但结果是......
Expression in WITH must be aliased (use AS) (line 2, column 6)
"WITH n.inputID, collect(n) AS nodes"
^
谢谢,
答案 0 :(得分:15)
您不是WITH
变量的别名。改变这个:
WITH n.inputID, collect(n) AS nodes
对此:
WITH n.inputID AS inputID, collect(n) AS nodes
答案 1 :(得分:2)
正如您所知,在集合上使用tail将允许您删除重复项,不要忘记在节点之前删除关系(DETACH)并将字段别名为FrobberOfBits:
MATCH (n:Input)
WITH n.inputID AS inputID, collect(n) AS nodes
WHERE size(nodes) > 1
FOREACH (n in tail(nodes) | DETACH DELETE n)