πŸ“MongoDB

This service is responsible for connecting to the MongoDB database.

Imports

import { MongoDBService } from 'niro-health';

Environment Variables

Do you create variables an .env file.

name
description

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.

.env
MONGODB_USERNAME=mongodb
MONGODB_PASSWORD=mongodb
MONGODB_HOST=localhost
MONGODB_PORT=27017
MONGODB_NAME=project_development
MONGODB_GRIDFS_NAME=project_development_gridfs
MONGODB_CONNECTION_SSL=false
MONGODB_PROJECT_NAME=niro_health

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.

Interface
Service

Properties

Property
Scope
Description

app

public

The application instance.

_mongoConfig

private

The MongoDB configuration.

Methods

Method
Scope
Description

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