1

将元素附加到集合并确保该元素仅在集合中出现一次的最佳方法是什么?

基本上我有一个标签列表并想附加新标签。类似于下面的查询,除了 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;
4

2 回答 2

0
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;
于 2013-11-04T20:30:53.043 回答
0

您应该考虑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;
于 2013-09-24T13:05:42.933 回答