Hector Hector - 1 year ago 82
Java Question

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();

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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download