🔧 refactor: Move MongoDB connection logic to a separate module and make database name optional

This commit is contained in:
Ruben Talstra 2025-06-15 12:04:55 +02:00
parent cffd66054e
commit 6a811c708b
No known key found for this signature in database
GPG key ID: 2A5A7174A60F3BEA
2 changed files with 53 additions and 5 deletions

View file

@ -1,7 +1,6 @@
require('dotenv').config();
const mongoose = require('mongoose');
const MONGO_URI = process.env.MONGO_URI;
const MONGO_DB_NAME = process.env.MONGO_DB_NAME;
if (!MONGO_URI) {
throw new Error('Please define the MONGO_URI environment variable');
@ -34,10 +33,6 @@ async function connectDb() {
// useCreateIndex: true
};
if (MONGO_DB_NAME) {
opts.dbName = MONGO_DB_NAME;
}
mongoose.set('strictQuery', true);
cached.promise = mongoose.connect(MONGO_URI, opts).then((mongoose) => {
return mongoose;