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 { MongooseSchemaCollectorModule } from '@eleven-labs/nest-profiler-mongoose';
import { MongooseSchemaCollector } from '@eleven-labs/nest-profiler-mongoose';

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

Setup

profiling/profiling.module.ts
// In the dev-only profiling bundle's imports:
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()). The collector resolves it by token, so it needs no wiring in the modules that use @nestjs/mongoose; pass connectionName for a named connection.

ProfilingModule is the dev-only bundle loaded by main-dev.ts — see Enabling and disabling the profiler. If the profiler is installed as a production dependency behind the runtime gate, wrap the same call in ConditionalModule.registerWhen(..., isProfilerEnabled).

Async setup

Drive the options from ConfigService (or any provider) with forRootAsync(), registered in the same bundle. It resolves option values only — for the enabled flag and when to prefer forRoot, see Enabling and disabling the profiler.

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

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

On this page