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

**URL:** https://community.forestadmin.com/t/cant-manage-to-start-local-nest-js-app-with-integrated-forest-admin-agent/7285
**Category:** Help me!
**Created:** [June 28, 2024, 2:34pm UTC](https://community.forestadmin.com/t/cant-manage-to-start-local-nest-js-app-with-integrated-forest-admin-agent/7285 "2024-06-28T14:34:56Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![thbleed3r](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/thbleed3r/32/7102_2.png) [@thbleed3r](https://community.forestadmin.com/u/thbleed3r)
#### Post date: [June 28, 2024, 2:34pm UTC](https://community.forestadmin.com/t/cant-manage-to-start-local-nest-js-app-with-integrated-forest-admin-agent/7285/1 "2024-06-28T14:34:56Z")

</div>

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

```javascript
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'
  }).addDataSource(
      createMongoDataSource({
          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,
    },
    httpsOptions
  });
  app.use(compression());

  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)

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

```

it starts ok  
Can anyone please help me with this ?

---

<div class="post-metadata">

### Author: ![anon62739609](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@anon62739609](https://community.forestadmin.com/u/anon62739609)
#### Post date: [June 28, 2024, 3:47pm UTC](https://community.forestadmin.com/t/cant-manage-to-start-local-nest-js-app-with-integrated-forest-admin-agent/7285/2 "2024-06-28T15:47:30Z")

</div>

Hi @thbleed3r and welcome in our community 🍾,

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

---

<div class="post-metadata">

### Author: ![thbleed3r](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/thbleed3r/32/7102_2.png) [@thbleed3r](https://community.forestadmin.com/u/thbleed3r)
#### Post date: [July 1, 2024, 9:41am UTC](https://community.forestadmin.com/t/cant-manage-to-start-local-nest-js-app-with-integrated-forest-admin-agent/7285/3 "2024-07-01T09:41:25Z")

</div>

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

```javascript
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)

```

---

<div class="post-metadata">

### Author: ![anon62739609](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@anon62739609](https://community.forestadmin.com/u/anon62739609)
#### Post date: [July 1, 2024, 11:31am UTC](https://community.forestadmin.com/t/cant-manage-to-start-local-nest-js-app-with-integrated-forest-admin-agent/7285/4 "2024-07-01T11:31:33Z")

</div>

Could you try to reduce the introdspection properties ([cf documentation](https://docs.forestadmin.com/developer-guide-agents-nodejs/data-sources/provided-data-sources/mongodb#introspection)) ?  
So reducing `collectionSampleSize`, `referenceSampleSize` and `maxPropertiesPerObject`

---

<div class="post-metadata">

### Author: ![thbleed3r](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/thbleed3r/32/7102_2.png) [@thbleed3r](https://community.forestadmin.com/u/thbleed3r)
#### Post date: [July 1, 2024, 12:12pm UTC](https://community.forestadmin.com/t/cant-manage-to-start-local-nest-js-app-with-integrated-forest-admin-agent/7285/5 "2024-07-01T12:12:33Z")

</div>

Same error  
Looking through the docs in NodeJs examples I see

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

const agent = createAgent(options).addDataSource(
  createMongoDataSource({
    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

---

<div class="post-metadata">

### Author: ![Alban\_Bertolini](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/alban_bertolini/32/1077_2.png) [@Alban\_Bertolini](https://community.forestadmin.com/u/Alban_Bertolini)
#### Post date: [July 1, 2024, 1:34pm UTC](https://community.forestadmin.com/t/cant-manage-to-start-local-nest-js-app-with-integrated-forest-admin-agent/7285/6 "2024-07-01T13:34:38Z")

</div>

Hello,  
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.

🙏

---

<div class="post-metadata">

### Author: ![thbleed3r](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/thbleed3r/32/7102_2.png) [@thbleed3r](https://community.forestadmin.com/u/thbleed3r)
#### Post date: [July 1, 2024, 1:44pm UTC](https://community.forestadmin.com/t/cant-manage-to-start-local-nest-js-app-with-integrated-forest-admin-agent/7285/7 "2024-07-01T13:44:13Z")

</div>

Yes, I configured the introspection object:

```javascript
          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:  
`mongodb://localhost:27017/{collectionName}`  
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

---

<div class="post-metadata">

### Author: ![Alban\_Bertolini](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/alban_bertolini/32/1077_2.png) [@Alban\_Bertolini](https://community.forestadmin.com/u/Alban_Bertolini)
#### Post date: [July 2, 2024, 7:26am UTC](https://community.forestadmin.com/t/cant-manage-to-start-local-nest-js-app-with-integrated-forest-admin-agent/7285/8 "2024-07-02T07:26:25Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Alban\_Bertolini](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/alban_bertolini/32/1077_2.png) [@Alban\_Bertolini](https://community.forestadmin.com/u/Alban_Bertolini)
#### Post date: [July 3, 2024, 11:33am UTC](https://community.forestadmin.com/t/cant-manage-to-start-local-nest-js-app-with-integrated-forest-admin-agent/7285/9 "2024-07-03T11:33:49Z")

</div>

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