Mongo connection is kept idle although i'm done with the query

I’m setting up a simple example but the connection is still open even after i got the response

const options = {};
        if (process.env.APPLICATION_MONGODB_AUTH_USERNAME && process.env.APPLICATION_MONGODB_AUTH_PASSWORD) {
            options.auth = {
                username : process.env.APPLICATION_MONGODB_AUTH_USERNAME,
                password : process.env.APPLICATION_MONGODB_AUTH_PASSWORD,
            }
            options.authSource =  process.env.APPLICATION_MONGODB_AUTH_SOURCE ? process.env.APPLICATION_MONGODB_AUTH_SOURCE : "admin";
        }
        const client = new MongoClient(process.env.APPLICATION_MONGODB_CONNECTION_URL, options);
        return await client.connect().then(async () => {
            const database = client.db(process.env.APPLICATION_MONGODB_SSO_DB);
            const collection = database.collection('loginAttemptLog');
            return collection.find({}).toArray();
        }).finally(async () => {
// do i have to explicitly close it here every time??
            await client.close();
            console.log('MongoDB connection closed');
        });```

am i doing something wrong? do i have to manually close the connection every time i do a query?

connections may be pooled locally for performance reasons.

can’t get what you mean
my question is do i have to explicitly await client.close(); after every open connection?

No. Keep the client for the lifetime of the application.

:bulb: Reuse Your Client

As each MongoClient represents a pool of connections to the database, most applications only require a single instance of a MongoClient, even across multiple requests. To learn more about how connection pools work in the driver, see the FAQ page.