【问题标题】:Neo4j: Iterate through collection of relationships and set property to indexNeo4j:遍历关系集合并将属性设置为索引
【发布时间】:2015-03-31 02:22:50
【问题描述】:

在经典的 for(i etc.){ ... } 样式中,我想遍历有序集合 - 伪代码:

for n,i in nodes
  set node.weight = i + 1
end

可行吗?

【问题讨论】:

    标签: neo4j


    【解决方案1】:

    是的,但不是最漂亮的东西:

    MATCH ...
    WITH COLLECT(something) AS nodes
    FOREACH(i IN RANGE(0, LENGTH(nodes)) |
        FOREACH(node IN [nodes[i]] |
            SET node.weight = i + 1
    ))
    

    【讨论】:

    • 将它放入neo4j.rb 的方法很简单,但它确实有效!
    • @Nicole White:既然这不“漂亮”,那是否意味着 Neo4j 有意不强调这些编程结构?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-23
    • 1970-01-01
    • 1970-01-01
    • 2018-11-17
    • 1970-01-01
    相关资源
    最近更新 更多