neo4j追加独特的收藏品

时间:2013-09-23 17:09:35

标签: neo4j cypher

将元素追加到集合中以及确保元素在集合中只出现一次的最佳方法是什么?

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

2 个答案:

答案 0 :(得分: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;

答案 1 :(得分: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;
相关问题