cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How to create database name in Bolt Driver?

lingvisa
Graph Fellow

I used to only create one database so I used the default database name 'neo4j-default'. Now I need to create one more database, and I want to explicitly give the db a name. How to do that?

I thought I should change this line:

my_driver = GraphDatabase.driver(self.uri, auth=(self.username, self.password), encrypted=False)

But it doesn't seem to have a parameter to give the DB a name. How to do that? My community version is 4.0.4.

3 REPLIES 3

andreperez
Graph Buddy

Is this the official Python driver or the Py2Neo?
If it's the official one you can do this:

with driver.session(database="example_database", fetch_size=100) as session:
    result = session.run("MATCH (a:Person) RETURN a.name AS name")
    # do something with the result...

More information here:
https://neo4j.com/docs/api/python-driver/current/api.html?highlight=database#session-construction

And here:
https://neo4j.com/docs/api/python-driver/current/api.html?highlight=database#database-ref

If you are using Py2Neo, there's an optional "nam" parameter to state which Database you'd like to connect.

https://py2neo.org/v5/database.html#the-graph

I am using Python official bolt api. Regarding the 'fetch_size',

The fetch size used for requesting messages from Neo4j.

Does this mean for each cypher request, or read_transaction, it returns the number of fetch_size records from the DB? How is it related to the 'limit' keyword in cypher statement?

with driver.session(database="example_database", fetch_size=100) as session:
    result = session.run("MATCH (a:Person) RETURN a.name AS name")

Actually, I was asking for how to create a db with a db name, not how to connect to a specific db. This statement below gives me the 'default' neo4j db name:
my_driver = GraphDatabase.driver(self.uri, auth=(self.username, self.password), encrypted=False)