@nestjs/mongoose#MongooseModule TypeScript Examples

The following examples show how to use @nestjs/mongoose#MongooseModule. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: app.module.ts    From nestjs-file-streaming with MIT License 10 votes vote down vote up
@Module({
  imports: [
    MongooseModule.forRoot(
      `mongodb://${
        process.env.NODE_ENV === 'docker' ? 'streaming-api-db' : 'localhost'
      }:27017/streaming`,
      {
        useUnifiedTopology: true,
        useNewUrlParser: true,
      },
    ),
    MongooseModule.forFeature([{ name: 'fs.files', schema: FileModel }]),
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}
Example #2
Source File: courses.service.spec.ts    From codeclannigeria-backend with MIT License 6 votes vote down vote up
describe('CoursesService', () => {
  let service: CoursesService;

  beforeEach(async () => {
    const module: TestingModule = await Test.createTestingModule({
      imports: [
        DbTest,
        MongooseModule.forFeature([
          { name: Course.modelName, schema: Course.schema }
        ])
      ],
      providers: [CoursesService]
    }).compile();

    service = await module.resolve<CoursesService>(CoursesService);
  });

  it('should be defined', () => {
    expect(service).toBeDefined();
  });
});
Example #3
Source File: mailer.module.ts    From uniauth-backend with MIT License 6 votes vote down vote up
@Module({
  imports: [
    MongooseModule.forFeature([{ name: User.name, schema: UserSchema }]),
    JwtModule.register({
      secret: confirmEmailTokenConstants.secret,
      signOptions: { expiresIn: confirmEmailTokenConstants.expiresIn },
    }),
    UserModule,
    WinstonModule.forRoot(logger.console()),
  ],
  controllers: [MailerController],
  providers: [MailerService],
  exports: [MailerService],
})
export class MailerModule {}
Example #4
Source File: recommendation.module.ts    From Phantom with MIT License 6 votes vote down vote up
@Module({
  imports: [
    SharedModule,
    MongooseModule.forFeature([
      { name: 'Board', schema: Board },
      { name: 'Pin', schema: Pin },
      { name: 'Topic', schema: Topic },
      { name: 'User', schema: User },
    ]),
  ],
  controllers: [RecommendationController],
  providers: [RecommendationService],
  exports: [RecommendationService],
})
export class RecommendationModule {}
Example #5
Source File: user.module.ts    From uniauth-backend with MIT License 6 votes vote down vote up
@Module({
  imports: [
    MongooseModule.forFeatureAsync([
      {
        name: 'User',
        useFactory: () => {
          const schema = UserSchema;
          schema.plugin(mongooseUniquevalidator);
          return schema;
        },
      },
    ]),
    WinstonModule.forRoot(logger.console()),
  ],
  controllers: [UserController],
  providers: [UserService],
  exports: [UserService],
})
export class UserModule {}
Example #6
Source File: pins.module.ts    From Phantom with MIT License 6 votes vote down vote up
@Module({
  imports: [
    SharedModule,
    BoardModule,
    ImagesModule,
    MongooseModule.forFeature([
      { name: 'Pin', schema: Pin },
      { name: 'Board', schema: Board },
      { name: 'Topic', schema: Topic },
      { name: 'User', schema: User },
    ]),
  ],
  controllers: [PinsController],
  providers: [PinsService],
  exports: [PinsService],
})
export class PinsModule {}
Example #7
Source File: MongooseTestModule.ts    From uniauth-backend with MIT License 6 votes vote down vote up
rootMongooseTestModule = (options: MongooseModuleOptions = {}) =>
  MongooseModule.forRootAsync({
    useFactory: async () => {
      mongod = new MongoMemoryServer();
      const mongoUri = await mongod.getUri();
      return {
        uri: mongoUri,
        ...options,
      };
    },
  })
Example #8
Source File: chat.module.ts    From Phantom with MIT License 6 votes vote down vote up
@Module({
  imports: [
    SharedModule,
    MongooseModule.forFeature([
      { name: 'User', schema: User },
      { name: 'Chat', schema: Chat },
      { name: 'Message', schema: Message },

    ]),
  ],
  controllers: [ChatController],
  providers: [ChatService],
  exports: [ChatService],
})
export class ChatModule { }
Example #9
Source File: auth.service.spec.ts    From codeclannigeria-backend with MIT License 6 votes vote down vote up
describe('AuthService', () => {
  let service: AuthService;

  beforeEach(async () => {
    const module = await Test.createTestingModule({
      imports: [
        DbTest,
        MongooseModule.forFeature([
          { name: TemporaryToken.modelName, schema: TemporaryToken.schema }
        ]),
        UsersModule
      ],
      providers: [AuthService, TempTokensService]
    }).compile();

    service = module.get<AuthService>(AuthService);
  });

  it('should be defined', () => {
    expect(service).toBeDefined();
  });
});
Example #10
Source File: app.module.ts    From Phantom with MIT License 6 votes vote down vote up
@Module({
  imports: [
    MongooseModule.forRoot(process.env.CONNECTION_STRING),
    PinsModule,
    BoardModule,
    ImagesModule,
    TopicModule,
    SharedModule,
    AuthModule,
    UserModule,
    SearchModule,
    ChatModule,
    RecommendationModule,
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}
Example #11
Source File: categories.service.spec.ts    From codeclannigeria-backend with MIT License 6 votes vote down vote up
describe('CategoriesService', () => {
  let service: CategoriesService;

  beforeEach(async () => {
    const module: TestingModule = await Test.createTestingModule({
      imports: [
        DbTest,
        MongooseModule.forFeature([
          { name: Category.modelName, schema: Category.schema }
        ])
      ],
      providers: [CategoriesService]
    }).compile();

    service = await module.resolve<CategoriesService>(CategoriesService);
  });

  it('should be defined', () => {
    expect(service).toBeDefined();
  });
});
Example #12
Source File: infrastructure.module.ts    From nest-js-products-api with MIT License 6 votes vote down vote up
static foorRoot(setting: any): DynamicModule {
    return {
      module: InfrastructureModule,
      imports: [
        ApplicationModule,
        MongooseModule.forRootAsync({
          imports: [ConfigModule],
          useFactory: async (configService: ConfigService) => ({
            uri: `mongodb://${configService.get(db_uri)}:${setting.port ||
              configService.get(db_port)}/${configService.get(db_name)}`,
          }),
          inject: [ConfigService],
        }),
        MongooseModule.forFeature([{ name: 'Product', schema: ProductSchema }]),
      ],
      controllers: [ProductController],
    };
  }
Example #13
Source File: search.module.ts    From Phantom with MIT License 6 votes vote down vote up
@Module({
  imports: [
    SharedModule,
    MongooseModule.forFeature([
      { name: 'Board', schema: Board },
      { name: 'Pin', schema: Pin },
      { name: 'User', schema: User },
    ]),
  ],
  controllers: [SearchController],
  providers: [SearchService],
})
export class SearchModule {}
Example #14
Source File: application.module.ts    From nest-js-products-api with MIT License 6 votes vote down vote up
@Module({
  imports: [
    DomainModule,
    MongooseModule.forFeature([
      {
        name: 'Product',
        schema: ProductSchema,
      },
    ]),
  ],
  providers: [
    ProductFactory,
    GetAllProductsUseCase,
    GetProductUseCase,
    CreateProductUseCase,
    DeleteProductUseCase,
    UpdateProductUseCase,
    {
      provide: 'ProductRepository',
      useClass: ProductRepositoryMongo,
    },
  ],
  exports: [
    ProductFactory,
    GetAllProductsUseCase,
    GetProductUseCase,
    CreateProductUseCase,
    DeleteProductUseCase,
    UpdateProductUseCase,
  ],
})
export default class ApplicationModule {}
Example #15
Source File: user.module.ts    From edu-server with MIT License 6 votes vote down vote up
@Module({
  imports: [
    MongooseModule.forFeature([
      { name: 'User', schema: UserSchema },
      { name: 'Course', schema: CourseSchema },
      { name: 'Enrolled', schema: EnrolledCourseSchema },
    ]),
  ],
  controllers: [UserController],
  providers: [UserService],
})
export class UserModule {}
Example #16
Source File: db-test.module.ts    From codeclannigeria-backend with MIT License 6 votes vote down vote up
dbFactory = MongooseModule.forRootAsync({
  useFactory: async () => {
    const uri = await dbServer.getUri();
    return {
      useNewUrlParser: true,
      useUnifiedTopology: true,
      useCreateIndex: true,
      useFindAndModify: false,
      uri
    };
  }
})
Example #17
Source File: app.module.ts    From whispr with MIT License 6 votes vote down vote up
@Module({
  imports: [
    TerminusModule,
    GraphQLModule.forRootAsync<ApolloDriverConfig>({
      imports: [ConfigModule],
      driver: ApolloDriver,
      useFactory: async (configService: ConfigService) => ({
        autoSchemaFile: configService.get('AUTO_SCHEMA_FILE'),
        introspection: configService.get('INTROSPECTION'),
        playground: false,
        cors: false,
        plugins: configService.get('PLAYGROUND') ? [ApolloServerPluginLandingPageLocalDefault()] : [],
        installSubscriptionHandlers: true,
      }),
      inject: [ConfigService],
    }),
    MongooseModule.forRootAsync({
      imports: [ConfigModule],
      useFactory: async (configService: ConfigService) => configService.getMongooseOptions(),
      inject: [ConfigService],
    }),
    PubSubModule,
    WhispModule,
    TagGroupModule,
    TagModule,
    SequenceModule,
    ConfigModule,
    AWSCredsModule,
    FileModule,
    DistributionModule,
    EventModule,
    WebhookModule,
    AuthModule,
  ],
  providers: [AppService],
  controllers: [AppController, HealthController],
})
export class AppModule {}
Example #18
Source File: users.module.ts    From nest-js-boilerplate with MIT License 6 votes vote down vote up
@Module({
  imports: [
    MongooseModule.forFeature([{
      name: User.name,
      schema: UserSchema,
    }]),
  ],
  controllers: [UsersController],
  providers: [UsersService, UsersRepository],
  exports: [UsersService, UsersRepository],
})
export default class UsersModule {}
Example #19
Source File: shared.module.ts    From Phantom with MIT License 6 votes vote down vote up
@Module({
  imports: [
    MongooseModule.forFeature([
      { name: 'User', schema: User },
      { name: 'Pin', schema: Pin },
      { name: 'Board', schema: Board },
      { name: 'Topic', schema: Topic },
      { name: 'Message', schema: Message },
      { name: 'Chat', schema: Chat },
    ]),
  ],
  providers: [
    SharedGateway,
    ChatService,
    ValidationService,
    Email,
    NotificationService,
    {
      provide: APP_FILTER,
      useClass: HttpExceptionFilter,
    },
    {
      provide: APP_INTERCEPTOR,
      useClass: LoggingInterceptor,
    },
  ],
  exports: [NotificationService, ValidationService, Email],
})
export class SharedModule { }
Example #20
Source File: app.module.ts    From nestjs-tenancy with MIT License 6 votes vote down vote up
@Module({
    imports: [
        MongooseModule.forRoot('mongodb://localhost:27017/test'),
        TenancyModule.forRoot({
            tenantIdentifier: 'X-TENANT-ID',
            options: () => { },
            uri: (tenantId: string) => `mongodb://localhost/test-tenant-${tenantId}`,
        }),
        CatsModule,
        DogsModule,
    ],
})
export class AppModule { }
Example #21
Source File: tag.module.ts    From whispr with MIT License 6 votes vote down vote up
@Module({
  imports: [
    MongooseModule.forFeature([{ name: 'Tag', schema: tagSchema }]),
    MongooseModule.forFeature([{ name: 'TagGroup', schema: tagGroupSchema }]),
    DistributionModule,
    FileModule,
    SequenceModule,
  ],
  controllers: [TagController],
  providers: [TagService, TagGroupService, TagResolver],
  exports: [TagService],
})
export class TagModule {}
Example #22
Source File: user.module.ts    From Phantom with MIT License 6 votes vote down vote up
@Module({
  imports: [
    SharedModule,
    MongooseModule.forFeature([
      { name: 'User', schema: User },
      { name: 'Pin', schema: Pin },
      { name: 'Board', schema: Board },
      { name: 'Topic', schema: Topic },
      { name: 'Message', schema: Message },
      { name: 'Chat', schema: Chat },
    ]),
  ],
  controllers: [UserController],
  providers: [UserService, BoardService],
  exports: [UserService],
})
export class UserModule { }
Example #23
Source File: MongooseTestModule.ts    From whispr with MIT License 6 votes vote down vote up
rootMongooseTestModule = (options: MongooseModuleOptions = {}) => MongooseModule.forRootAsync({
  useFactory: async () => {
    mongod = await MongoMemoryServer.create();
    const mongoUri = mongod.getUri();
    return {
      uri: mongoUri,
      ...options,
    };
  },
})
Example #24
Source File: app.module.ts    From adminjs-nestjs with MIT License 6 votes vote down vote up
@Module({
  imports: [
    MongooseModule.forRoot('mongodb://localhost:27017/nest'),
    AdminModule.createAdminAsync({
      imports: [
        MongooseSchemasModule,
      ],
      inject: [
        getModelToken('Admin'),
      ],
      useFactory: (adminModel: Model<Admin>) => ({
        adminJsOptions: {
          rootPath: '/admin',
          resources: [
            { resource: adminModel },
          ],
        },
        auth: {
          authenticate: async (email, password) => Promise.resolve({ email: 'test' }),
          cookieName: 'test',
          cookiePassword: 'testPass',
        },
      }),
      customLoader: ExpressCustomLoader,
    }),
    MongooseSchemasModule,
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule { }
Example #25
Source File: topic.module.ts    From Phantom with MIT License 6 votes vote down vote up
@Module({
  imports: [
    SharedModule,
    UserModule,
    MongooseModule.forFeature([
      { name: 'Topic', schema: Topic },
      { name: 'Pin', schema: Pin },
      { name: 'User', schema: User },
    ]),
  ],
  controllers: [TopicController],
  providers: [TopicService],
})
export class TopicModule {}
Example #26
Source File: app.module.ts    From uniauth-backend with MIT License 6 votes vote down vote up
/**
 * Main Application Module
 * @category Module
 */
@Module({
  imports: [
    MongooseModule.forRoot(config.get('database.string'), mongooseConfig),
    UserModule,
    ApplicationModule,
    AuthModule,
    AccountModule,
    DashboardModule,
    WinstonModule.forRoot({
      transports: [
        new winston.transports.Console({
          format: winston.format.combine(
            winston.format.timestamp(),
            nestWinstonModuleUtilities.format.nestLike(),
            winston.format.colorize(),
          ),
        }),
        new winston.transports.File({ filename: 'application.log' }),
        new winston.transports.File({ filename: 'error.log', level: 'error' }),
      ],
    }),
  ],
  controllers: [AppController],
})
export class AppModule {}
Example #27
Source File: seeder.ts    From nestjs-seeder with MIT License 5 votes vote down vote up
seeder({
  imports: [
    MongooseModule.forRoot('mongodb://localhost/nestjs-seeder-sample'),
    MongooseModule.forFeature([{ name: User.name, schema: userSchema }]),
  ],
}).run([UsersSeeder]);
Example #28
Source File: app.module.ts    From NextJS-NestJS-GraphQL-Starter with MIT License 5 votes vote down vote up
@Module({
  imports: [
    MongooseModule.forRoot(MONO_DB_CONNECTION_STRING, {
      useCreateIndex: true,
      useNewUrlParser: true,
    }),
    MongooseModule.forFeature([...schemas]),
    GraphQLModule.forRoot({
      installSubscriptionHandlers: true,

      cors: {
        origin: CORS_ORIGIN,
        optionsSuccessStatus: 200,
        credentials: true,
      },
      plugins: [SentryPlugin],
      engine: {
        // The Graph Manager API key
        apiKey: ENGINE_API_KEY,
        // A tag for this specific environment (e.g. `development` or `production`).
        // For more information on schema tags/variants, see
        // https://www.apollographql.com/docs/platform/schema-registry/#associating-metrics-with-a-variant
        schemaTag: ENV,
      },
      autoSchemaFile: 'schema.gql',
      context: ({ req, res, connection }) => {
        const clientId = get(connection, 'context.clientId');
        return { req, res, ...(clientId && { clientId }) };
      },
    }),
    AuthModule,
    ChatModule,
    UserModule,
  ],
  controllers: [HealthzController],
  providers: [...services, ...resolvers],
})
export class AppModule {
  configure(consumer: MiddlewareConsumer) {
    consumer.apply(AuthMiddleware).forRoutes('*');
  }
}
Example #29
Source File: chat.module.ts    From edu-server with MIT License 5 votes vote down vote up
@Module({
  imports: [MongooseModule.forFeature([{ name: 'Chat', schema: ChatSchema }])],
  controllers: [ChatController],
  providers: [ChatService],
})
export class ChatModule {}