Socket
Socket
Sign inDemoInstall

@nestlab/mongo

Package Overview
Dependencies
73
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @nestlab/mongo

Mongo DB module for NestJS


Version published
Weekly downloads
19
increased by216.67%
Maintainers
1
Created
Weekly downloads
 

Readme

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

FAQs

Last updated on 29 Jan 2021

Did you know?

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc