NestJS Profiler
API Reference

nest-profiler-mongoose

Types and API of the Mongoose query collector.

MongooseCollectorModuleOptions

Options passed to MongooseCollectorModule.forRoot().

Prop

Type

MongooseQueryEntry

One entry per Mongoose query or aggregation executed during a request.

Prop

Type

Public exports

import { MongooseCollectorModule } from '@eleven-labs/nest-profiler-mongoose';
import { MongooseCollector } from '@eleven-labs/nest-profiler-mongoose';

import type {
  MongooseCollectorModuleOptions,
  MongooseCollectorModuleAsyncOptions,
  MongooseQueryEntry,
} from '@eleven-labs/nest-profiler-mongoose';

Setup

// In ReviewsModule (or any module that uses @nestjs/mongoose):
MongooseCollectorModule.forRoot({
  slowThreshold: 50, // ms — queries at/above this are tagged 'slow'
});

Prerequisite: MongooseModule.forRoot() must be registered in the application (provides Connection globally via @InjectConnection()).

Async setup

Drive the options from ConfigService (or any provider) with forRootAsync(), gated per environment with ConditionalModule (recommended). It resolves option values only — for the enabled flag and when to prefer forRoot, see Enabling and disabling the profiler.

import { ConditionalModule, ConfigService } from '@nestjs/config';
import { MongooseCollectorModule } from '@eleven-labs/nest-profiler-mongoose';

const isProfilerEnabled = (env: NodeJS.ProcessEnv) => env['PROFILER_ENABLED'] !== 'false';

ConditionalModule.registerWhen(
  MongooseCollectorModule.forRootAsync({
    inject: [ConfigService],
    useFactory: (config: ConfigService) => ({
      slowThreshold: config.get<number>('PROFILER_SLOW_QUERY_MS') ?? 50,
    }),
  }),
  isProfilerEnabled,
);
Powered & maintained by

On this page