0

I am new to MongoDB. How to list all databases of mongodb through Simba JDBC driver. have tried alot but I am only able to get the name of database through which I have build the connection URL. Even, I am not sure that, is this possible or not to get the list of all databases?

I have tried this way: Class.forName("com.simba.mongodb.jdbc4.Driver");

        Connection conn = DriverManager              
          .getConnection("jdbc:mongodb://admin:admin@localhost:27017/admin);

      //In the getConnection parameters, last admin is the name of database. 

        DatabaseMetaData dbmd = conn.getMetaData();

        ResultSet ctlgs = dbmd.getCatalogs();

        while (ctlgs.next()){
            System.out.println("ctlgs="+ctlgs.getString(1));
        }

But, it only gives the connected database name. Appreciate help.

Nishant
  • 53
  • 5

2 Answers2

0

In connection url , set property LoadMetadataTable as true , by default it was false. e.g. jdbc:mongodb://jsmith:pass12345@localhost:18000/TeamRoster?A uthMechanism=SCRAM-SHA-1&LoadMetadataTable=true

stranger
  • 1
  • 1
0

I got the answer while playing with Simba jdbc driver for mongodb. Actually, in connection string, database name is mandatory. Now, if authentication is enabled from mongodb side then, we will get only one database name as output which has been mentioned in connection string. And if, authentication is disabled then, we will get the list of all databases as an output.

Nishant
  • 53
  • 5