@voiceflow/nestjs-mongodb
TypeScript icon, indicating that this package has built-in type declarations

1.3.0 • Public • Published

NestJS MongoDB

MongoDB, but for NestJS

Installation

yarn add @voiceflow/nestjs-mongodb mongodb
yarn add -D @types/mongodb

Usage

The mongo module can be setup in a couple different ways using forRootAsync:

  • A MongoOptions object can be provided via useValue.
  • A useFactory function can be provided to return a MongoOptions object (or a promise for one!).
  • A class implementing MongoOptions can be provided using useClass.
import { MongoModule, MongoService, MongoOptions } from '@voiceflow/nestjs-mongodb';

@Module({
  imports: [
    MongoModule.forRootAsync({
      imports: [],

      // Union field, one of `useValue`, `useFactory`, or `useClass`:
      useValue: {
        url: 'mongodb://<auth>@<your-mongo-db-address>/<db_name>?<params>',
      },
      useFactory: () => getMongoConfig(),
      useClass: MongoConfigService,
    }),
  ],
})
export class AppModule {}

If you have an existing redis connection that you'd like to reuse, you can provide that in forRoot.

import { MongoClient } from 'mongodb';

const mongoConnection = MongoClient.connect(...)

@Module({
  imports: [
    MongoModule.forRoot(mongoConnection),
  ],
})
export class AppModule {}

Once the MongoModule is globally registered, MongoService can be injected in other providers without having to import MongoModule again.

/@voiceflow/nestjs-mongodb/

    Package Sidebar

    Install

    npm i @voiceflow/nestjs-mongodb

    Weekly Downloads

    120

    Version

    1.3.0

    License

    ISC

    Unpacked Size

    17.4 kB

    Total Files

    20

    Last publish

    Collaborators

    • cheatcod
    • ebra-vf
    • saargue
    • ganeshasapu
    • gillyb
    • ose-voiceflow
    • theprof
    • bhuvana.adur.kannan
    • abuyak
    • e_vandenberg
    • ninabondar
    • yoyotruly
    • matthewnaik
    • edison-vflow
    • shelone.grantwatson
    • zhilight
    • amandasteinhauer
    • pmvrmc
    • filipemerker
    • viniciusdacal
    • trs
    • matheuspoleza
    • denyslinkov
    • andrewlawrence
    • tylerhhan
    • effervescentia
    • josh_vf
    • voiceflow-gallagan
    • z4o4z
    • xavidop
    • vf-serviceaccount