Moved the query parameter into the correct position and added logging for the final URI for database connect.
This commit is contained in:
@@ -3,19 +3,23 @@ const catchAsyncErrors = require("../Middlewares/catchAsyncErrors.js");
|
||||
|
||||
const DB_connect = catchAsyncErrors(async () => {
|
||||
try {
|
||||
const connectionInstance = await mongoose.connect(
|
||||
`${process.env.MONGODB_URI}/${process.env.DATABASE_NAME}`
|
||||
);
|
||||
const dbUri = `${process.env.MONGODB_URI}/${process.env.DATABASE_NAME}?authSource=admin`;
|
||||
const connectionInstance = await mongoose.connect(dbUri, {
|
||||
useNewUrlParser: true,
|
||||
useUnifiedTopology: true,
|
||||
});
|
||||
|
||||
if (!connectionInstance) {
|
||||
console.log("MongoDB connection failed");
|
||||
}
|
||||
console.log(
|
||||
"MongoDB connected Successfully on server : " +
|
||||
} else {
|
||||
console.log(
|
||||
"MongoDB connected Successfully to:",
|
||||
connectionInstance.connection.host
|
||||
);
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("MongoDB connection failed due to some error :", error);
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = DB_connect;
|
||||
|
||||
Reference in New Issue
Block a user