How to connect mongo with nestJs?

Viewed 369

If I config mongo with nest js its come like this, enter image description here

my files like this,

app.module.ts

enter image description here

item.schema.ts

enter image description here

items.module.ts

enter image description here

items.service.ts

enter image description here

2 Answers

I use a forwardRef in the other modules where I declare the mongo models like this:

@Module({
 imports: [
     forwardRef(() => AppModule),
     MongooseModule.forFeature([{ name: 'User', schema: UserSchema }])
]
})

Where AppModule my app.module is

Just remove the ItemsService from the AppModule and exports it on your ItemsModule, besides no need to define the ItemsController on the AppModule it's enough to be defined on the ItemsModule.

You may have a look about contollers and exports following this link https://docs.nestjs.com/modules

Related