Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Neo4j python driver to connect to multiple database

I have a Neo4j instance setup Neo4j 4.0 - Enterprise edition. I created a 2 database through UI

Docs on managing multiple databases here: https://neo4j.com/developer/manage-multiple-databases/

Databases:

  1. system (this sytem database)
  2. neo4j (default database)
  3. Db1 (this is my newly created database 1)
  4. Db2 (this is my newly created database 2)

Neo4j python official driver doesn't have the option to connect to the database (Db1, Db2)

Connection: GraphDatabase.driver("bolt://0.0.0.0:7687/", auth=('xx', "xx"), encrypted=False)

There is no parameter to mention what database to use. Any help on this is appreciated. Thanks in advance.

like image 646
Swaroop Avatar asked Jul 30 '26 18:07

Swaroop


1 Answers

The driver is database-agnostic, and can access multiple databases via distinct sessions. database= is a session parameter. Example below for Db1:

driver = GraphDatabase.driver("bolt://0.0.0.0:7687/", auth=('xx', "xx"), encrypted=False)
session = driver.session(database='Db1')

Python Driver 4.0 Documentation

like image 168
Cobra Avatar answered Aug 02 '26 06:08

Cobra



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!