1

I have a list of words (strings). Using python3 and official neo4j driver I'm trying to create nodes. One node - one word from list.

Here is my code:

for word in lst:
    query = "CREATE (" + word + ":Word {word:'" + word + "})"
    session.run(query)

I can run it and it works for small amount of words. But if to increase size of list (like 100000) - neo4j creates only a part of nodes.

I suppose, it can't process in time my queries. Is there any solution to create a large number of nodes in my case?

starrabb1t
  • 49
  • 1
  • 9

1 Answers1

1

Doing this might help.

#Execute a given query
def executeQuery(query):
    tx = session.begin_transaction()
    result = tx.run(query)
    tx.commit()
    return result

for word in lst:
    query = "CREATE (" + word + ":Word {word:'" + word + "})"
    executeQuery(query)
krishna reddy
  • 295
  • 2
  • 15
  • I've read about sessions and transactions in the docs, but this way is not easy for understanding: https://neo4j.com/docs/api/python-driver/current/transactions.html#sessions – starrabb1t Jun 26 '19 at 09:33
  • There is a clear explanation of sessions and transactions: https://stackoverflow.com/questions/39525713/session-run-vs-transaction-run-in-neo4j-bolt – starrabb1t Jun 26 '19 at 09:33