Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get all database names in neo4j using python?

from neo4j import GraphDatabase

driver = GraphDatabase.driver("bolt://localhost:7687", auth=("neo4j", "password"))

with driver.session() as session:
        result = session.run("SHOW DATABASES")
        print(result)

the result is <neo4j.work.result.Result object at 0x0000028F2BB30208>

How to get database names?

like image 588
santosh kumar Avatar asked Jan 18 '26 07:01

santosh kumar


1 Answers

This will show you only the DATABASES names in cypher-shell:

  SHOW DATABASES yield name;

Example from python:

test.py

from neo4j import GraphDatabase

driver = GraphDatabase.driver("bolt://localhost:7687", auth=("neo4j", "password"))

with driver.session() as session:
    result = session.run("SHOW DATABASES yield name;")
    for line in result:
        print(line['name'])

When executed:

 python test.py 
 neo4j
 system
  

Tested in neo4j 4.2.1 , openjdk 11.0.15 2022-04-19 , python 3.7.0 , Ubuntu 20.04.4

like image 153
R2D2 Avatar answered Jan 20 '26 21:01

R2D2