mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-22 06:00:56 +02:00

* chore: Comment out deprecated MongoDB connection options in connectDb.js * replaced deprecrated MongoDB count() function with countDocuments() * npm audit fix (package-lock cleanup) * chore: Specify .env file in launch configuration * feat: gemini-2.0 * chore: bump express to 4.21.2 to address CVE-2024-52798 * chore: remove redundant comment for .env file specification in launch configuration --------- Co-authored-by: neturmel <neturmel@gmx.de>
45 lines
1.1 KiB
JavaScript
45 lines
1.1 KiB
JavaScript
require('dotenv').config();
|
|
const mongoose = require('mongoose');
|
|
const MONGO_URI = process.env.MONGO_URI;
|
|
|
|
if (!MONGO_URI) {
|
|
throw new Error('Please define the MONGO_URI environment variable');
|
|
}
|
|
|
|
/**
|
|
* Global is used here to maintain a cached connection across hot reloads
|
|
* in development. This prevents connections growing exponentially
|
|
* during API Route usage.
|
|
*/
|
|
let cached = global.mongoose;
|
|
|
|
if (!cached) {
|
|
cached = global.mongoose = { conn: null, promise: null };
|
|
}
|
|
|
|
async function connectDb() {
|
|
if (cached.conn && cached.conn?._readyState === 1) {
|
|
return cached.conn;
|
|
}
|
|
|
|
const disconnected = cached.conn && cached.conn?._readyState !== 1;
|
|
if (!cached.promise || disconnected) {
|
|
const opts = {
|
|
bufferCommands: false,
|
|
// useNewUrlParser: true,
|
|
// useUnifiedTopology: true,
|
|
// bufferMaxEntries: 0,
|
|
// useFindAndModify: true,
|
|
// useCreateIndex: true
|
|
};
|
|
|
|
mongoose.set('strictQuery', true);
|
|
cached.promise = mongoose.connect(MONGO_URI, opts).then((mongoose) => {
|
|
return mongoose;
|
|
});
|
|
}
|
|
cached.conn = await cached.promise;
|
|
return cached.conn;
|
|
}
|
|
|
|
module.exports = connectDb;
|