0

Kindly help me to resolve this issue. I am following the tutorial on this link: https://www.kernix.com/blog/an-efficient-recommender-system-based-on-graph-database_p9 . I am unable to modify the following so that it could comply with the new format of py2neo v3 where graph.run is used instead of graph.cypher.begin(). The purpose of the code below is to Create the nodes relative to Users, each one being identified by its user_id and "MERGE" request : creates a new node if it does not exist already

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()

Thank you very much in advance

HuongLeY
  • 1
  • 1

1 Answers1

1

With v3 of py2neo your snippet would look like this:

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() is a method on the Graph class, which will create a new transaction. Transaction.run will send a Cypher statement to the server for execution - but not commit the transaction until Transaction.commit is called.

William Lyon
  • 8,371
  • 1
  • 17
  • 22