diff --git a/src/lib/achievementsDB.js b/src/lib/achievementsDB.js index e45745c..50717b4 100644 --- a/src/lib/achievementsDB.js +++ b/src/lib/achievementsDB.js @@ -14,9 +14,10 @@ import mongoose from "mongoose"; // } // }; const connectToAchievementsDB = async () => { - if (mongoose.connection.readyState >= 1) { - console.log("✅ Already connected to Achievements MongoDB"); - return; + if (mongoose.connection.readyState >= 1) { + console.log("⚠️ Existing connection found. Closing it..."); + await mongoose.connection.close(); + console.log("✅ Previous connection closed"); } try { diff --git a/src/lib/db.js b/src/lib/db.js index 0b5b641..34ae384 100644 --- a/src/lib/db.js +++ b/src/lib/db.js @@ -1,7 +1,11 @@ import mongoose from "mongoose"; const connectToDatabase = async () => { - if (mongoose.connection.readyState >= 1) return; + if (mongoose.connection.readyState >= 1) { + console.log("⚠️ Existing connection found. Closing it..."); + await mongoose.connection.close(); + console.log("✅ Previous connection closed"); + }; try { await mongoose.connect(process.env.MongoURL, { diff --git a/src/lib/event.ts b/src/lib/event.ts index 6b252cb..efaa712 100644 --- a/src/lib/event.ts +++ b/src/lib/event.ts @@ -2,7 +2,11 @@ import mongoose from "mongoose"; const connectToEventDB = async () => { - if (mongoose.connection.readyState >= 1) return; + if (mongoose.connection.readyState >= 1) { + console.log("⚠️ Existing connection found. Closing it..."); + await mongoose.connection.close(); + console.log("✅ Previous connection closed"); + }; try { await mongoose.connect(process.env.MongoURL!, { diff --git a/src/lib/teamDB.ts b/src/lib/teamDB.ts index c28ddb3..8de1ecc 100644 --- a/src/lib/teamDB.ts +++ b/src/lib/teamDB.ts @@ -2,7 +2,11 @@ import mongoose from "mongoose"; const connectToTeamDB = async () => { - if (mongoose.connection.readyState >= 1) return; + if (mongoose.connection.readyState >= 1) { + console.log("⚠️ Existing connection found. Closing it..."); + await mongoose.connection.close(); + console.log("✅ Previous connection closed"); + }; try { await mongoose.connect(process.env.MongoURL!, {