A utility class for MongoDB operations. This class is not meant to be instantiated.

MongoEssentials

Throws an error if an attempt is made to instantiate the class.

static connectToMongoDB Connects to a MongoDB database using the provided connection string.

The connection string to connect to MongoDB.

A promise that resolves to the MongoClient instance if the connection is successful.

Will throw an error if the connection string is not provided or is not a string.

Will throw an error if the connection attempt fails or times out.

const client = await MongoEssentials.connectToMongoDB('mongodb://localhost:27017/mydb');

Constructors

Methods

Constructors

Methods

  • Connects to a MongoDB database using the provided connection string.

    Parameters

    • connectionString: string

      The connection string to connect to MongoDB.

    Returns Promise<MongoClient>

    A promise that resolves to the MongoClient instance if the connection is successful.

    Will throw an error if the connection string is not provided or is not a string.

    Will throw an error if the connection attempt fails or times out.

    const client = await MongoEssentials.connectToMongoDB('mongodb://localhost:27017/mydb');