如何在Neo4J中设置和更新列表属性?

时间:2017-11-01 10:28:27

标签: neo4j

我想知道是否可以按索引更新节点或边缘的列表属性。

MATCH (t1:t)-[r1:o]->(a:a)<-[r2:o]-(t2:t) where r1.loc-r2.loc=-1 and r1.month=r2.month
WITH t1,t2,count(t1) as c
MERGE (t1)-[r:r]->(t2)
ON CREATE SET r.weights = "empty array of size 12(months) with array[month]=c
ON MATCH  SET r.weights[month] = r.weights[month]+c

我想可以用以下类似的方法设置空数组:

ON CREATE SET r.weights = reduce(a=[], i in range(0,month-1) | a + [0])+[c]+reduce(a=[], i in range(0,12-month) | a + [0])

但更新列表属性的最佳方法是什么?

谢谢!

1 个答案:

答案 0 :(得分:0)

我设法通过以下方式解决它:

MATCH (t1:t)-[r1:o]->(a1:a)<-[r2:o]-(t2:t) where r1.loc-r2.loc=-1 and r1.month=r2.month

WITH t1,r1,t2,r2,count(t1) as c

MERGE (t1)-[r:r]->(t2)

ON CREATE SET r.weights = reduce(a=[], i in range(0,r1.month-2) | a + [0])+[c]+reduce(a=[], i in range(0,11-r1.month) | a + [0])

ON MATCH SET r.weights = reduce(a=[], e in r.weights[0..r1.month-1]+[r.weights[r1.month-1]+c]+r.weights[r1.month..13] |a+e)
return t1,t2,c,r