Can't manage to start local nest js app with integrated forest admin agent

Hello, I’m trying to integrate forestadmin into my nestjs project
Environment: dev
DB: mongodb
Here is my main.ts file :

import { NestFactory } from '@nestjs/core';
import * as compression from 'compression';
import './initEnv';
import { NestExpressApplication } from '@nestjs/platform-express';
import { HttpsOptions } from '@nestjs/common/interfaces/external/https-options.interface';
import { AppModule } from './app.module';
import { createAgent } from '@forestadmin/agent'
import { createMongoDataSource } from '@forestadmin/datasource-mongo';

async function bootstrap() {
  let httpsOptions: HttpsOptions

  const agent = createAgent({
    authSecret: process.env.FOREST_AUTH_SECRET,
    envSecret: process.env.FOREST_ENV_SECRET,
    isProduction: process.env.ENV === 'prod',
    logger: (logLevel, message) => {
      console.error(logLevel, message);
    loggerLevel: 'Error', // Valid values are 'Debug', 'Info', 'Warn' and 'Error'
          uri: 'mongodb://localhost:27017/test',
          dataSource: { flattenMode: 'auto' },
  const app = await NestFactory.create<NestExpressApplication>(AppModule, {
    cors: {
      origin: ['http://localhost:4302', 'http://localhost:4200'],
      methods: ['GET', 'PUT', 'POST', 'PATCH', 'DELETE', 'OPTIONS'],
      allowedHeaders: ['Content-Type', 'Authorization'],
      exposedHeaders: ['Authorization'],
      credentials: true,

  await agent.mountOnNestJs(app).start();

  await app.listen(3000)
bootstrap().catch((err) => process.stderr.write(err + '\n'));

when I run my app it logs:

Info Successfully mounted on NestJS
RangeError: Maximum call stack size exceeded

if I remove the db name here (or if I give it a name that does not exist)

          uri: 'mongodb://localhost:27017(/lqmskdfgjhl)',
          dataSource: { flattenMode: 'auto' },

it starts ok
Can anyone please help me with this ?

Hi @thbleed3r and welcome in our community :champagne:,

Could you try with flattenMode: 'none' ?
Could you share the error logs too it would really help?

I tried with flattenMode : 'none', same result
here is the error log

RangeError: Maximum call stack size exceeded
    at String.split (<anonymous>)
    at MongooseSchema.getSubSchema (XXXXXXXX/node_modules/@forestadmin/datasource-mongoose/src/mongoose/schema.ts:134:35)

Could you try to reduce the introdspection properties (cf documentation) ?
So reducing collectionSampleSize, referenceSampleSize and maxPropertiesPerObject

Same error
Looking through the docs in NodeJs examples I see

const { createAgent } = require('@forestadmin/agent');
const { createMongooseDataSource } = require('@forestadmin/datasource-mongo');

const agent = createAgent(options).addDataSource(
    uri: 'mongodb://localhost:27017', // no db name here
    dataSource: { flattenMode: 'auto' },

is it correct , or they missed the db name ( it’s a question I have to ask myself, looking at the createMongooseDataSource import line ) ?

anyway when i run the code without db name i.e. mongodb://localhost:27017
the app starts with no errors , but I can’t see any collection in my forest admin (since the connection uri is not pointing to a specific database ? )

I’m a bit confused about how to make this thing work

Indeed, the documentation is broken. The import does not work:

const { createMongooseDataSource } = require('@forestadmin/datasource-mongo');

Should be

const { createMongoDataSource } = require('@forestadmin/datasource-mongo');

I’ll fix it, thank you for the report.

Did you try to configure the introspection to reduce the introspection scope? (Vince message). The Introspection will read on your collections to compute your forestadmin interface. Sometimes, the computation is too big because you have a huge database.

anyway when i run the code without db name

If you don’t provide a collection name, we will introspect the default db, in your case it is empty. That why there is no collection in your forestadmin.


Yes, I configured the introspection object:

          introspection: {
            collectionSampleSize: 1, // how many documents are sampled per collection
            referenceSampleSize: 1, // how many references are taken to deduce relationships
            maxPropertiesPerObject: 1, // how many properties should be extracted out as columns

and you can see in the code I provided that I use a collection name in the db uri:
I’m kind of out of options here, and I dont know if it’s something wrong with the way i try to implement Forest Admin or maybe something is broken in the source code

To resume:

  1. When you call createMongoDataSource it throws “Maximum call stack size” error.
  2. If you configure introspection object, what do you have as result?

Can I have a schema of your database? Or a sample to try to reproduce on my side. You can send me a private message if it is confidential.

After some investigations, the datasource has a bug with the version 6. The version 7 works. I will create a bug ticket.