or run

tessl search
Log in

Version

Files

tile.json

task.mdevals/scenario-8/

Mongo Connection Module

Create a NestJS module that configures a MongoDB connection for the application. The module should support both synchronous and asynchronous configuration paths and allow consumers to request either the default connection or a named connection.

Capabilities

Synchronous connection setup

  • Registering the module with a MongoDB URI and optional database name produces a NestJS module that starts with a live connection and exposes an injectable connection token usable by providers. @test

Asynchronous options factory

  • Registering the module with an async options factory waits for the factory result before creating the connection and passes through properties such as URI, database name, retry attempts, and retry delay. @test

Custom connection name

  • Providing a connection name yields an injectable connection token scoped to that name while keeping the default connection unchanged. @test

Implementation

@generates

API

export interface DatabaseModuleOptions {
  uri: string;
  dbName?: string;
  connectionName?: string;
  retryAttempts?: number;
  retryDelay?: number;
  lazyConnection?: boolean;
}

export interface DatabaseModuleAsyncOptions {
  useFactory: (...args: any[]) => Promise<DatabaseModuleOptions> | DatabaseModuleOptions;
  inject?: any[];
  connectionName?: string;
}

export class DatabaseModule {
  static register(options: DatabaseModuleOptions): DynamicModule;
  static registerAsync(options: DatabaseModuleAsyncOptions): DynamicModule;
}

Dependencies { .dependencies }

@nestjs/mongoose { .dependency }

Provides NestJS integration with MongoDB connections and injectable connection tokens.

@nestjs/config { .dependency }

Supplies configuration values for building async database options.