import { MongoClient, Db } from 'mongodb'; if (!process.env.MONGODB_URI) { throw new Error('Please add your MongoDB URI to .env.local'); } const uri = process.env.MONGODB_URI; const options = {}; let client: MongoClient; let clientPromise: Promise; if (process.env.NODE_ENV === 'development') { const globalWithMongo = global as typeof globalThis & { _mongoClientPromise?: Promise; }; if (!globalWithMongo._mongoClientPromise) { client = new MongoClient(uri, options); globalWithMongo._mongoClientPromise = client.connect(); } clientPromise = globalWithMongo._mongoClientPromise; } else { client = new MongoClient(uri, options); clientPromise = client.connect(); } export async function getDatabase(): Promise { const client = await clientPromise; return client.db('librechat'); // Nom de votre base de données } export default clientPromise;