Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IMAGINE AI Update db.js #1338

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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