// lib/mongodb.ts import { MongoClient, Db } from 'mongodb'; const uri = process.env.MONGODB_URI; let client: MongoClient; let clientPromise: Promise; if (!uri) { throw new Error('Please add your Mongo URI to.env.local'); } // client = new MongoClient(uri,{ // maxPoolSize: 5, // maxConnecting:5, // maxIdleTimeMS: 3000, // waitQueueTimeoutMS: 1000 // }); // clientPromise = client.connect(); // export const getDb = async () => { // const client = await clientPromise; // return client.db('ai-bot') // }; // export const getCollection = async (collection: string) => { // const client = await clientPromise; // return client.db('ai-bot').collection(collection); // }; const ins = new MongoClient(uri,{ maxPoolSize: 5, maxConnecting:5, maxIdleTimeMS: 3000, waitQueueTimeoutMS: 1000 }).db('ai-bot') export const getDb = async () => { return ins }; export const getCollection = async (collection: string) => { return ins.collection(collection); };