Skip to content

Commit

Permalink
Merge pull request #1338 from Nidhibansalll/patch-1
Browse files Browse the repository at this point in the history
IMAGINE AI Update db.js
  • Loading branch information
SurajPratap10 authored Oct 28, 2024
2 parents 8dcb3da + 90bb40b commit fb26a7c
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions config/db.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@

// i just made some changes so that it can add connection options to improve performance and handle potential issues and want to log more details about the error, such as the error code so that it ,may create more easiness and reusble of code.


const mongoose = require("mongoose");

mongoose.set("strictQuery", true);

const connectDb = async () => {
const uri = process.env.MONGODB_URI;

if (!uri) {
console.error("Please set the MONGODB_URI environment variable.");
process.exit(1);
}

try {
const connect = await mongoose.connect(uri, {});
const connect = await mongoose.connect(uri, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
console.log(`Connected to Db: ${connect.connection.host}`);
} catch (error) {
console.log(`MongoDb connection Error:${error}`);
console.error(`MongoDB connection error: ${error.message}`);
}
};

Expand Down

0 comments on commit fb26a7c

Please sign in to comment.