Should I make a NEW mongodb.client.connect() for every DB operation?

I am randomly getting an error:

MongoServerClosedError: Server is closed

I am using nodejs and mongodb, but NOT using Mongoose…

Here is my basic MongoDBConnector.js code:

const MongoClient = require('mongodb').MongoClient;
const uri = process.env.MONGO_URI;
const db_name = process.env.DB_NAME;

const client = new MongoClient(uri, { useNewUrlParser: true, useUnifiedTopology: true });

//insert document into mongodb atlas
const insertDocument = async (collectionName, document) => {

    try {
        await client.connect();
        const database = client.db(db_name);
        const collection = database.collection(collectionName);
        const result = await collection.insertOne(document);
        return result;

    } catch (error) {
  } finally {
        await client.close();

…as you can see, I am creating the client.connect() every time I call insertDocument() DB operation and then client.close() at the end of the operation, yet I keep getting the:

MongoServerClosedError: Server is closed error

I use the same approach for all my database operations, such as getDocument() and updateDocument(), where I use

await client.connect();

to connect for every operation and

await client.close();

at the end of every operation. Yet I am still sometimes getting the error

MongoServerClosedError: Server is closed error

To me it seems like the asynchronous client.connnect() and client.close() commands should only be used ONCE, and the insertDocument() and other DB operations should be able to RESUSE the client connection.

Can anyone offer an opinion on this? I followed a tutorail that said to do it the way I did, but I think there must be a better way to implement my client.connect() and reuse it for all my DB operations.

Many thanks for anyone interested in replying

Having the same issue. Any update on that?