From 1b1addfa4216b1b16c13533cdce7eb81e4c2b348 Mon Sep 17 00:00:00 2001 From: Dieter Blocher Date: Wed, 29 Jan 2025 19:24:15 +0000 Subject: [PATCH] Format stuff --- src/middleware/database.js | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/middleware/database.js b/src/middleware/database.js index bdd1ecc..a106f6b 100644 --- a/src/middleware/database.js +++ b/src/middleware/database.js @@ -4,24 +4,25 @@ const connectDB = async () => { const conn = await mongoose.connect('mongodb://mongodb:27017/tombola', { }); console.log(`MongoDB Connected: ${conn.connection.host}:${conn.connection.port}`); - // Get and log database stats - const dbStats = await conn.connection.db.stats(); - console.log("Database Stats:", dbStats); + // Get and log database stats + const dbStats = await conn.connection.db.stats(); + console.log("Database Stats:", dbStats); - // Get and log all collections in the database - const collections = await conn.connection.db.collections(); - console.log("Collections:"); - collections.forEach(collection => { - console.log(collection.collectionName); - }); + // Get and log all collections in the database + const collections = await conn.connection.db.collections(); + if (collections.length > 0) { + console.log("Collections:"); + collections.forEach(collection => { + console.log(collection.collectionName); + }); + // Get and log the indexes of a specific collection (optional) + const collectionName = "collectionname"; // Replace with your collection name + const indexes = await conn.connection.db.collection(collectionName).indexes(); + console.log(`Indexes in ${collectionName}:`); + console.log(indexes); + } - // Get and log the indexes of a specific collection (optional) - //const collectionName = "tombola"; // Replace with your collection name - //const indexes = await conn.connection.db.collection(collectionName).indexes(); - //console.log(`Indexes in ${collectionName}:`); - //console.log(indexes); - - console.log("Finish Database Stats."); + console.log("Finish Database Stats."); } catch (error) { console.error(error.message);