import mongoose from 'mongoose';\n\nlet isConnected = false;\n\nexport async function connectDB() {\n  if (isConnected) return;\n\n  try {\n    await mongoose.connect(process.env.MONGODB_URI, {\n      useNewUrlParser: true,\n      useUnifiedTopology: true,\n    });\n    isConnected = true;\n    console.log('MongoDB connected');\n  } catch (error) {\n    console.error('MongoDB connection error:', error);\n    throw error;\n  }\n}