【发布时间】:2015-11-12 21:04:46
【问题描述】:
我有一个测试版网站,其中包含名为主题的节点。我忘记将唯一约束添加到 name 属性,现在有重复的节点。我使用 MERGE 希望它能找到唯一的名称并添加关系,但显然情况并非如此。无论如何将所有关系合并到单个节点,然后删除重复项,以便在清理约束后添加约束?
我找到了这个,但我有多个具有不同关系的节点。有人知道如何修改它以适应我的情况吗?
//编辑
使用 Michael 的代码,我将块修改为:
MATCH (t:Topic)
WITH t.name as name, collect(t) as topics, count(*) as cnt
WHERE cnt > 1
WITH head(topics) as first, tail(topics) as rest
LIMIT 1000
UNWIND rest AS to_delete
OPTIONAL MATCH (to_delete)-[r:TOPIC_OF]->(g:Group)
FOREACH (x in case when r is null then [] else [1] |
MERGE (first)-[new_r:TOPIC_OF]->(g)
// in case you have to copy-rel-properties
SET new_r = r
DELETE r
)
OPTIONAL MATCH (to_delete)<-[r2:INTEREST_OF]-(p:Person)
FOREACH (x in case when r2 is null then [] else [1] |
MERGE (first)-[new_r2:INTEREST_OF]->(p)
// in case you have to copy-rel-properties
SET new_r2 = r2
DELETE r2
)
OPTIONAL MATCH (to_delete)<-[r3:SKILL_OF]-(p:Person)
FOREACH (x in case when r3 is null then [] else [1] |
MERGE (first)-[new_r3:SKILL_OF]->(p)
// in case you have to copy-rel-properties
SET new_r3 = r3
DELETE r3
)
OPTIONAL MATCH (to_delete)-[r4:TOPIC]->(p:Project)
FOREACH (x in case when r4 is null then [] else [1] |
MERGE (first)-[new_r4:TOPIC]->(p)
// in case you have to copy-rel-properties
SET new_r4 = r4
DELETE r4
)
OPTIONAL MATCH (to_delete)-[r5:NEEDS]->(p:Project)
FOREACH (x in case when r5 is null then [] else [1] |
MERGE (first)-[new_r5:NEEDS]->(p)
// in case you have to copy-rel-properties
SET new_r5 = r5
DELETE r5
)
DELETE to_delete
RETURN count(*);
运行时出现错误:
Invalid input '|': expected whitespace, comment, '.', node labels, '[', "=~", IN, STARTS, ENDS, CONTAINS, IS, '^', '*', '/', '%', '+', '-', '=', "<>", "!=", '<', '>', "<=", ">=", AND, XOR, OR or END (line 8, column 52 (offset: 276))
"FOREACH (x in case when r is null then [] else [1] |"
我错过了什么?
【问题讨论】:
-
你在使用 neoxygen/neoclient 吗?
-
是的,我正在使用 Neoclient