Hector
Hector

Reputation: 5356

List all MongoDB Databases and their details from Java

I am developing a Java/MongoDB application and require a list of all existing MongoDB Databases.

I know I can use this code:-

final MongoClient mongoClient = DatabaseManager.getMongoclient();

final ListDatabasesIterable<Document> databasesDocument = mongoClient.listDatabases();
final MongoCursor<Document> mongoCursor = databasesDocument.iterator();

while (mongoCursor.hasNext()) {
    final Document databaseDocument = mongoCursor.next();
    Assert.assertNotNull(databaseDocument);
}

However the details only include the Database Name, its size on disk, and whether or not the database is empty.

I need to know when the database was created, when = Date & Time.

Is there anyway I can retrieve this information from within a Java application?

Upvotes: 0

Views: 91

Answers (1)

Mike Shauneu
Mike Shauneu

Reputation: 3289

As far as I know, MongoDB doesn't keep track of database creation dates.

One possible workaround if you are creator of databases is tracking it by yourself. Create meta collection in meta database and insert new record db_name=time when you create database.

Upvotes: 1

Related Questions