import { MongoClient, ObjectId } from "mongodb";

export const database = process.env.MONGODB_DB;
const uri = `${process.env.MONGODB_URI}`;
const options = {
  maxPoolSize: 200,
  minPoolSize: 5,
  serverSelectionTimeoutMS: 10000,
  socketTimeoutMS: 60000,
  maxIdleTimeMS: 60000,
  monitorCommands: true,
};

const client = new MongoClient(uri, options);
const clientPromise = client.connect();

export const objectId = (id) =>
  typeof id === "string" ? new ObjectId(id) : id;

export default clientPromise;
