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'); Copy
const client = await MongoEssentials.connectToMongoDB('mongodb://localhost:27017/mydb');
Static
Connects to a MongoDB database using the provided connection string.
A utility class for MongoDB operations. This class is not meant to be instantiated.
MongoEssentials
Throws
Throws an error if an attempt is made to instantiate the class.
Method
static connectToMongoDB Connects to a MongoDB database using the provided connection string.
Param: connectionString
The connection string to connect to MongoDB.
Returns
A promise that resolves to the MongoClient instance if the connection is successful.
Throws
Will throw an error if the connection string is not provided or is not a string.
Throws
Will throw an error if the connection attempt fails or times out.
Example