在cypher收集的FOREACH

时间:2014-03-18 12:15:04

标签: foreach neo4j cypher

我有一组rels,使用此

创建
MATCH (u:user)-[i:INTEREST]->(t:term)
WITH COLLECT([i,t]) AS its
RETURN its

并正确返回rels和nodes数组。 另见http://console.neo4j.org/r/cw7saq

现在我想设置关系的属性,但是看不到我如何访问数组中的rels。试过这个,

MATCH (u:user)-[i:INTEREST]->(t:term)
WITH COLLECT([i,t]) AS its
FOREACH (it IN its |
         SET it[0].testprop=89292" )

但它返回错误

Error: Invalid input '[': expected an identifier character, node labels, a property map, a relationship pattern, '(', '.' or '=' (line 4, column 16)
"         SET it[0].testprop=89292" )"

任何人都知道这样做的正确语法是什么?

2 个答案:

答案 0 :(得分:3)

也不需要收集术语节点。请按以下步骤操作:

MATCH path=(u:user)-[i:INTEREST]->(t:term)
FOREACH (n IN rels(path) | set n.testprop=89292)

答案 1 :(得分:3)

任何遇到OP提到的子集错误的人都可以用括号解决它:

MATCH (u:user)-[i:INTEREST]->(t:term)
WITH COLLECT([i,t]) AS its
FOREACH (it IN its |
     SET (it[0]).testprop=89292" )