【问题标题】:How to create multiple node via looping in py2neo for neo4j如何通过在 py2neo 中为 neo4j 循环创建多个节点
【发布时间】:2017-09-06 02:48:34
【问题描述】:

请帮我解决这个问题。我正在关注此链接上的教程:https://www.kernix.com/blog/an-efficient-recommender-system-based-on-graph-database_p9。我无法修改以下内容,使其符合 py2neo v3 的新格式,其中使用 graph.run 而不是 graph.cypher.begin()。下面代码的目的是创建与用户相关的节点,每个节点都由其 user_id 和“MERGE”请求标识:如果新节点不存在,则创建一个新节点

tx = graph.cypher.begin()
statement = "MERGE (a:`User`{user_id:{A}}) RETURN a"
for u in user['id']:
    tx.append(statement, {"A": u})
tx.commit()

非常感谢您

【问题讨论】:

    标签: neo4j py2neo


    【解决方案1】:

    使用 v3 的 py2neo,您的 sn-p 将如下所示:

    tx = graph.begin()
    statement = "MERGE (a:`User`{user_id:{A}}) RETURN a"
    for u in user['id']:
        tx.run(statement, {"A": u})
    tx.commit()
    

    begin() 是 Graph 类上的一个方法,它将创建一个新事务。 Transaction.run 将向服务器发送 Cypher 语句以供执行 - 但在调用 Transaction.commit 之前不会提交事务。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多