module.exports = class mongodb_client {
    mongo_client

    constructor(url) {
        const {MongoClient} = require('mongodb')
        this.mongo_client = new MongoClient(url)
    }

    // database connect function
    async connect_database(database_name) {
        try {
            await this.mongo_client.connect()
            const database = this.mongo_client.db(database_name)
            console.log('Database connection status:', await database.command({ping: 1}))
            return database
        }
        catch(e) {
            console.error(e)
        }
        // finally
        // {
        //     await mongodb_client.close()
        //     console.log("Database connection closed")
        // }
    }
}