Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
07-24-2020 08:20 AM
I have created a database called 'foo' and i can switch to it in the browser and interact with it, but when I try to programmatically write to it using python neo4j library, I can only interact with the default database 'neo4j'. When I run the below code, it writes to 'neo4' database. Note the line that sets the driver session. Am I using this incorrectly?
thanks
from neo4j import GraphDatabase
import os
class HelloWorldExample:
def __init__(self, uri, user, password):
self.driver = GraphDatabase.driver(uri, auth=(user, password))
def close(self):
self.driver.close()
def print_greeting(self, message):
print(os.environ['NEO4J_DATABASE_NAME'])
with self.driver.session(database='foo') as session: # I expected this to work
greeting = session.write_transaction(self._create_and_return_greeting, message)
print(greeting)
@staticmethod
def _create_and_return_greeting(tx, message):
result = tx.run("CREATE (a:Greeting) "
"SET a.messsage = $message "
"RETURN a.message + ', from node ' + id(a)", message=message)
return result.single()[0]
if __name__ == "__main__":
AWS_DNS="ec2-xxxxx-32.compute-1.amazonaws.com"
greeter = HelloWorldExample("bolt://" + AWS_DNS + "/:7687", os.environ['NEO4J_USERNAME'], os.environ['NEO4J_PASSWORD'])
greeter.print_greeting("hello, world 13")
greeter.close()
02-07-2023 05:20 PM - edited 02-07-2023 05:33 PM
In case anyone hits this, you can use the py2neo package to specify the database :
Specify database in py2neo with Neo 4.0 - Neo4j - 52289
All the sessions of the conference are now available online