1.0.15 • Published 4 years ago

@nestlab/mongo v1.0.15

Weekly downloads
39
License
MIT
Repository
gitlab
Last release
4 years ago

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!

1.0.15

4 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago