From c846cc95e0a99e0755b2d14dee40263f4d080f9b Mon Sep 17 00:00:00 2001 From: gouravKJ Date: Sun, 27 Jul 2025 23:37:56 +0530 Subject: [PATCH] updated MongoDB --- server/configs/db.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) 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