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 () => {
|
const DB_connect = catchAsyncErrors(async () => {
|
||||||
try {
|
try {
|
||||||
const connectionInstance = await mongoose.connect(
|
const dbUri = `${process.env.MONGODB_URI}/${process.env.DATABASE_NAME}?authSource=admin`;
|
||||||
`${process.env.MONGODB_URI}/${process.env.DATABASE_NAME}`
|
const connectionInstance = await mongoose.connect(dbUri, {
|
||||||
);
|
useNewUrlParser: true,
|
||||||
|
useUnifiedTopology: true,
|
||||||
|
});
|
||||||
|
|
||||||
if (!connectionInstance) {
|
if (!connectionInstance) {
|
||||||
console.log("MongoDB connection failed");
|
console.log("MongoDB connection failed");
|
||||||
}
|
} else {
|
||||||
console.log(
|
console.log(
|
||||||
"MongoDB connected Successfully on server : " +
|
"MongoDB connected Successfully to:",
|
||||||
connectionInstance.connection.host
|
connectionInstance.connection.host
|
||||||
);
|
);
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log("MongoDB connection failed due to some error :", error);
|
console.log("MongoDB connection failed due to some error :", error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = DB_connect;
|
module.exports = DB_connect;
|
||||||
|
|||||||
Reference in New Issue
Block a user