MongoDB
This service is responsible for connecting to the MongoDB database.
Imports
Environment Variables
Do you create variables an .env
file.
MONGODB_USERNAME
Username of the mongodb.
MONGODB_PASSWORD
Password of the mongodb.
MONGODB_HOST
Host of the mongodb.
MONGODB_PORT
Port of the mongodb.
MONGODB_NAME
Database name of the mongodb.
MONGODB_GRIDFS_NAME
Database gridfs name of the mongodb.
MONGODB_CONNECTION_SSL
SSL connection of the mongodb.
MONGODB_PROJECT_NAME
Project name of the mongodb.
Check the example file.
Method of Use
To use this module, you need to inject it into the desired service.
Injecting the module into our service.
Modifying our main.ts
With dependencies
You will need to inject the following interfaces.
IAppHostService
IConfigurationService
IValidatorRegexpService
IStringExService
IDebugService
Properties
app
public
The application instance.
_mongoConfig
private
The MongoDB configuration.
Methods
onModuleInit
public
Initialize the module.
_initialize
private
Initialize the MongoDB connection.
_uri
private
Create the MongoDB connection URI.
_connectionLogs
private
MongoDB connection logs.
_connectionClose
private
MongoDB connection close.
_connectionOpen
private
MongoDB connection open.
getDB
public
Create a new Db instance sharing the current socket connections.
shutdown
public
Close the current connection.
onApplicationShutdown
public
Application shutdown hook.
enableShutdownHooks
public
Enable shutdown hooks.
Last updated