// config/database.js
const mongoose = require("mongoose");

const connectDB = async () => {
  try {
    
    // await mongoose.connect(
    //   `mongodb://${process.env.DB_USER_NAME}:${process.env.DB_PASSWORD}@${process.env.MONGO_URI}/${process.env.DB_NAME}?authSource=admin`,
    // );


    // local db
    //   await mongoose.connect(
    //   `mongodb://${process.env.MONGO_URI}/${process.env.DB_NAME}`
    // );

    console.log("✅ MongoDB Connected...");
    console.log("Connected DB:", mongoose.connection.name);
  } catch (err) {
    console.error("❌ MongoDB connection failed:", err.message);
    process.exit(1);
  }
};

module.exports = connectDB;
