Mongo module

You can use mongoose in your projects

Install @nestgram/mongo and mongoose

npm i @nestgram/mongo mongoose
npm i @types/mongoose --save-dev
// or
yarn add @nestgram/mongo mongoose
yarn add @types/mongoose -D

Connect mongoose

app.module.ts
import { Module } from 'nestgram';
import { UseMongoConnection } from '@nestgram/mongo';

import { AppController } from './app.controller';
import { AppService } from './app.service';

@Module({
  controllers: [AppController],
  services: [AppService],
  modules: [
    UseMongoConnection('uri'), // pass uri here
  ],
})
export class AppModule {}

Create schema

Import schema

Get the schema in the service

Then

You can then use the model in service methods and call it in controllers

Last updated