//**
//** @desc : Connect to mongodb using mongoose liberary
//**    source : https://mongoosejs.com/docs/connections.html
//**
//Todo 1 - Dont forget to add your mongodb connection uri as DB_URI in the .env.local

import mongoose from 'mongoose';

const connection : any = {};

async function dbConnect() {
    if (connection.isConnected) {
        return;
    }
    const db = await mongoose.connect(process.env.DB_URI?? '', {
        // @ts-ignore
        useNewUrlParser: true,
        useUnifiedTopology: true,
    });
    console.log('db connected successfully')
    connection.isConnected = db.connections[0].readyState;
}

export default dbConnect;