diff --git a/server/configs/db.js b/server/configs/db.js index c9c0cae..9072e2b 100644 --- a/server/configs/db.js +++ b/server/configs/db.js @@ -1,14 +1,21 @@ import mongoose from "mongoose"; - +//connecting to MongoDB const connectDB = async () => { - try { - mongoose.connection.on('connected', () => { - console.log('Database connected'); - }); - await mongoose.connect(`${process.env.MONGODB_URI}/hotel-booking`); - } catch (error) { - console.log(error.message); - } + mongoose.connection.on("connected",()=>{ + console.log("MongoDB connected successfully"); + }); + mongoose.connection.on("error", (err) => { + console.error(`MongoDB connection error: ${err}`); + }); + try{ + await mongoose.connect(`${process.env.MONGODB_URI}/hotel-booking`,{ + useNewUrlParser: true, + useUnifiedTopology: true, + }); + + } catch (error) { + console.error('error connecting to MongoDb:',error.message); + } }; export default connectDB; \ No newline at end of file