final fix for all api

This commit is contained in:
Ashwani Senapati
2025-11-29 18:10:02 +05:30
parent 8afb5012b2
commit 2fb1ea24b6
4 changed files with 19 additions and 6 deletions

View File

@@ -15,8 +15,9 @@ import mongoose from "mongoose";
// }; // };
const connectToAchievementsDB = async () => { const connectToAchievementsDB = async () => {
if (mongoose.connection.readyState >= 1) { if (mongoose.connection.readyState >= 1) {
console.log("✅ Already connected to Achievements MongoDB"); console.log("⚠️ Existing connection found. Closing it...");
return; await mongoose.connection.close();
console.log("✅ Previous connection closed");
} }
try { try {

View File

@@ -1,7 +1,11 @@
import mongoose from "mongoose"; import mongoose from "mongoose";
const connectToDatabase = async () => { 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 { try {
await mongoose.connect(process.env.MongoURL, { await mongoose.connect(process.env.MongoURL, {

View File

@@ -2,7 +2,11 @@ import mongoose from "mongoose";
const connectToEventDB = async () => { 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 { try {
await mongoose.connect(process.env.MongoURL!, { await mongoose.connect(process.env.MongoURL!, {

View File

@@ -2,7 +2,11 @@ import mongoose from "mongoose";
const connectToTeamDB = async () => { 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 { try {
await mongoose.connect(process.env.MongoURL!, { await mongoose.connect(process.env.MongoURL!, {