将元素附加到集合并确保该元素仅在集合中出现一次的最佳方法是什么?
基本上我有一个标签列表并想附加新标签。类似于下面的查询,除了 n.index 中的所有元素必须是唯一的
MATCH n, tag:Tag
WHERE n.id='22cfb053-f772-4a3a-83c4-bb733e3dac0a' AND tag.name='hello world'
SET n.index=n.index+tag.index
RETURN n;
MATCH n, tag:Tag
WHERE n.id='22cfb053-f772-4a3a-83c4-bb733e3dac0a' AND tag.name='hello world'
WITH n, FILTER(x IN n.index WHERE x <> tag.index) as filtered
SET n.index=filtered + tag.index
RETURN n;
您应该考虑Tag
通过TAGGED
关系将您的内容节点连接到节点。
对于组合集合,请使用文字集合和 +。n.index
已经必须是一个数组属性。
MATCH (n:Content), (tag:Tag)
WHERE n.id='22cfb053-f772-4a3a-83c4-bb733e3dac0a' AND tag.name='hello world'
SET n.index=n.index+[tag.index]
RETURN n;