假设我已经匹配了一系列关系:

MATCH a-[r:BELONGS_TO]->b

如何遍历每种关系并为其分配索引?用伪代码:
for i in range(0, # of r's)
  r.order = i

最佳答案

这应该工作:

MATCH (a)-[r:BELONGS_TO]->(b)
WITH collect(r) as rels
WITH rels, range(0, size(rels)) AS is
UNWIND is AS i
WITH rels[i] as rel, i
SET rel.order = i

10-05 21:30