那么,两步密码方法怎么样?使用 cypher 生成一些 cypher 语句,然后在 shell 中执行您的 cypher 语句。
您可以尝试这样的方法来生成批处理密码语句
match (n)
return distinct "match (n"
+ reduce( lbl_str= "", l in labels(n) | lbl_str + ":" + l)
+ ") remove n"
+ reduce( lbl_str= "", l in labels(n) | lbl_str + ":" + l)
+ ";"
输出应该是这样的......
match (n:Label_1:Label_2) remove n:Label_1:Label_2;
match (n:Label_1:Label_3) remove n:Label_1:Label_3;
match (n:Label_2:Label_4) remove n:Label_2:Label_4;
您可能希望删除所有重复项,并且根据您的数据,可能会有很多重复项。
不完全是您正在寻找的东西,但我认为仅使用 cypher 和 neo4j shell 就能使您达到相同的最终状态。
下面闪亮的新密码和改进密码...
我将其编辑为仅可在浏览器中使用的内容。它认为这是一个更好的解决方案。它仍然是两个步骤,但它会生成一个可以剪切并粘贴到浏览器中的语句。
match (n)
with distinct labels(n) as Labels
with reduce(lbl_str="", l in Labels | lbl_str + ":" + l) as Labels
order by Labels
with collect(Labels) as Labels
with Labels, range(0,length(Labels) - 1) as idx
unwind idx as i
return "match (n" + toString(i) + Labels[i] + ")" as Statement
union
match (n)
with distinct labels(n) as Labels
with reduce(lbl_str="", l in Labels | lbl_str + ":" + l) as Labels
order by Labels
with collect(Labels) as Labels
with Labels, range(0,length(Labels) - 1) as idx
unwind idx as i
return "remove n" + toString(i) + Labels[i] as Statement
产生这样的输出...
match (n0:Label_A)
match (n1:Label_B)
match (n2:Label_C:Label_D)
match (n3:Label_E)
remove n0:Label_A
remove n1:Label_B
remove n2:Label_C:Label_D
remove n3:Label_E
然后可以将其剪切并粘贴到 Neo4j 浏览器中。