How to use the @nestjs/mongoose.MongooseModule.forRoot function in @nestjs/mongoose

To help you get started, we’ve selected a few @nestjs/mongoose examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github djjorik / angular-chat / server / app.module.ts View on Github external
import { RoomsModule } from './rooms/rooms.module';
import { MongooseModule } from '@nestjs/mongoose';
import { CorsMiddleware } from './middlewares/cors.middleware';
import { AuthModule } from './auth/auth.module';


const getMongoUrl = () => {
  if (process.env.MONGOUSER && process.env.MONGOPASSWORD) {
    return `mongodb://${process.env.MONGOUSER}:${process.env.MONGOPASSWORD}@ds249839.mlab.com:49839/angular-nest-chat-app`;
  } else {
    return 'mongodb://localhost:27017/nest';
  }
};

@Module({
  imports: [MongooseModule.forRoot(getMongoUrl()),
    UsersModule,
    RoomsModule,
    AuthModule
  ],
  components: []
})
export class ApplicationModule {
  // configure(consumer: MiddlewaresConsumer): void {
  //   consumer.apply(CorsMiddleware).forRoutes('*');
  // }
}
github jkchao / blog-service / src / module / articles / __test__ / article.resolver.spec.ts View on Github external
beforeAll(async () => {
      const module = await Test.createTestingModule({
        imports: [
          MongooseModule.forRoot(config.MONGO_URL),
          ArticlesModule,
          GraphQLModule.forRoot({
            typePaths: ['./**/*.graphql'],
            path: '/api/v2',
            context: ({ req, res }: { req: Request; res: Response }) => ({
              request: req
            })
          })
        ]
      })
        .overrideProvider(ArticlesSercice)
        .useValue(articleService)
        .compile();

      app = await module.createNestApplication().init();
    });
github jkchao / blog-service / src / module / heros / __test__ / heros.resolver.spec.ts View on Github external
beforeAll(async () => {
      const module = await Test.createTestingModule({
        imports: [
          MongooseModule.forRoot(config.MONGO_URL),
          HerosModule,
          GraphQLModule.forRoot({
            typePaths: ['./**/*.graphql'],
            path: '/api/v2',
            context: ({ req, res }: { req: Request; res: Response }) => ({
              request: req
            })
          })
        ]
      })
        .overrideProvider(HerosService)
        .useValue(heroService)
        .overrideProvider(EmailService)
        .useValue(emailService)
        .compile();
github jkchao / blog-service / src / module / comments / __test__ / comments.resolver.spec.ts View on Github external
beforeAll(async () => {
      const module = await Test.createTestingModule({
        imports: [
          MongooseModule.forRoot(config.MONGO_URL),
          CommentsModule,
          GraphQLModule.forRoot({
            typePaths: ['./**/*.graphql'],
            path: '/api/v2',
            context: ({ req, res }: { req: Request; res: Response }) => ({
              request: req
            })
          })
        ]
      })
        .overrideProvider(CommentsService)
        .useValue(commentsService)
        .overrideProvider(ArticlesSercice)
        .useValue({
          findOneArticle() {
            return { _id: '123' };
github JamesCoonce / angular-nest-todo / server / todo-api / src / app.module.ts View on Github external
import { Module, NestModule } from '@nestjs/common';
import { MongooseModule } from '@nestjs/mongoose';
import { TodosModule } from './todos/todos.module';
import { UsersModule } from './users/users.module';
import { AuthModule } from './auth/auth.module';

@Module({
  imports: [
    MongooseModule.forRoot('mongodb://localhost/nest'),
    TodosModule,
    UsersModule,
    AuthModule],
  controllers: [],
  providers: [],
})
export class AppModule {}
github benawad / nest-mongo-graphql / src / app.module.ts View on Github external
import { Module } from '@nestjs/common';
import { GraphQLModule } from '@nestjs/graphql';
import { MongooseModule } from '@nestjs/mongoose';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { CatsModule } from './cats/cats.module';

@Module({
  imports: [
    CatsModule,
    GraphQLModule.forRoot({
      autoSchemaFile: 'schema.gql',
    }),
    MongooseModule.forRoot('mongodb://localhost/nest'),
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}
github vellengs / nestx / packages / server / src / app.module.ts View on Github external
import { Module } from '@nestjs/common';
import { MongooseModule } from '@nestjs/mongoose';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AuthModule } from './auth';
import { CoreModule } from './core';
import { CommerceModule } from './commerce';
import { CmsModule } from './cms';
import { MONGODB_URI } from './utils';
import { AppController } from './app.controller';
import { AppService } from './app.service';

@Module({
  imports: [
    TypeOrmModule.forRoot(),
    MongooseModule.forRoot(MONGODB_URI, {
      useCreateIndex: true,
      useNewUrlParser: true,
    }),
    AuthModule,
    CoreModule,
    CmsModule,
    CommerceModule,
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}
github nestjs / terminus / sample / 001-mongoose-app / src / health.module.ts View on Github external
} from '@nestjs/terminus';

const getTerminusOptions = (
  mongoose: MongooseHealthIndicator,
): TerminusModuleOptions => ({
  endpoints: [
    {
      url: '/health',
      healthIndicators: [async () => await mongoose.pingCheck('mongo')],
    },
  ],
});

@Module({
  imports: [
    MongooseModule.forRoot('mongodb://localhost:27017/test'),
    TerminusModule.forRootAsync({
      inject: [MongooseHealthIndicator],
      useFactory: getTerminusOptions,
    }),
  ],
})
export class HealthModule {}
github nestjs / nest / examples / 14-mongoose-module / src / modules / app.module.ts View on Github external
import { Module } from '@nestjs/common';
import { MongooseModule } from '@nestjs/mongoose';

import { CatsModule } from './cats/cats.module';
import { CatSchema } from './cats/schemas/cat.schema';

@Module({
  modules: [
    MongooseModule.forRoot('mongodb://localhost/nest', [
      { name: 'Cat', schema: CatSchema },
    ]),
    CatsModule,
  ],
})
export class ApplicationModule {}
github vellengs / nestx-server / src / app.module.ts View on Github external
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { MongooseModule } from '@nestjs/mongoose';

import { TypeOrmModule } from '@nestjs/typeorm';
import { AuthModule } from './auth/auth.module';
import { CoreModule } from './core/core.module';
import { CommerceModule } from './commerce/commerce.module';
import { CmsModule } from './cms/cms.module';

@Module({
  imports: [
    TypeOrmModule.forRoot(),
    MongooseModule.forRoot('mongodb://localhost/nestx-server'),
    AuthModule,
    CoreModule,
    CmsModule,
    CommerceModule,
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule { }