Socket
Book a DemoInstallSign in
Socket

@nestlab/mongo

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nestlab/mongo

Mongo DB module for NestJS

1.0.15
latest
Source
npmnpm
Version published
Weekly downloads
1
-94.74%
Maintainers
1
Weekly downloads
 
Created
Source

MongoModule

Installation

$ npm i @nestlab/mongo mongodb
$ npm i -D @types/mongodb

Configuration

Configuration for main module

import { MongoModule } from './mongo.module';

MongoModule.forRoot(
    [ // Connections
        {
            name: 'PRIMARY',
            uri: 'mongodb://localhost:27017/primary-database',
            reconnectionTimeout: 2000,
        },
        {
            name: 'SECONDARY',
            uri: 'mongodb://localhost:27017/secondary-database',
            reconnectionTimeout: 2000,
        },
    ], 
    [Entity1, Entity2], // Entities   
);

Configuration for feature module

import { MongoModule } from './mongo.module';

MongoModule.forFeature([ // Entities
    Entity3,
    Entity4,
]); 

Usage

Entity declaration

@Entity('cars') // Collection name
export class Car {
  name: string;
}

Inject connections

export class CarController {
    constructor(@InjectConnection('PRIMARY') primaryConnection: MongoConnection,
                @InjectConnection('SECONDARY') secondaryConnection: MongoConnection) {    
    } 
}

Inject repository

export class CarController {
    constructor(@InjectRepository(Car) carRepositry: Repository<Car>,
                @InjectRepository(Entity) entityRepository: Repository<Entity>) {    
    } 
}

Creation custom repositories

@EntityRepository(Car)
export class CarRepository extends Repository<Car> {
    // Your implementation...
}

Injection the same as in default repositories.

Enjoy!

Keywords

nestjs

FAQs

Package last updated on 29 Jan 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.