Nest can't resolve dependencies of the MongooseCoreModule (MongooseConnectionName, ?). Please make sure that the argument ModuleRef at index [1] is available in the MongooseCoreModule context.
I am new to nest and am facing this issue, the app.controller.ts is
import { Module } from '@nestjs/common';
import { ItemsController } from './items.controller';
import { ItemsService } from './items.service';
import { MongooseModule } from '@nestjs/mongoose';
import { ItemSchema } from './schema/item.schema';
@Module({
imports: [MongooseModule.forFeature([{name:'Item',schema:ItemSchema}])],
controllers: [ItemsController],
providers: [ItemsService],
})
export class ItemsModule {}
Any help would be appreciated
In you case, you can try to add this to your ItemSchema:
// schema/item.schema
@Schema({ collection: 'items' })
And make sure the import with a plural name:
// items.module.ts
// [...]
@Module({
imports: [MongooseModule.forFeature([{name:'items',schema:ItemSchema}])],
controllers: [ItemsController],
providers: [ItemsService],
})
export class ItemsModule {}
According to this question .
Or if you prefer to keep the name schema name item
, you can force it by following this answer
Mongoose is trying to be smart by making your collection name plural. You can however force it to be whatever you want:
var dataSchema = new Schema({..}, { collection: 'data' })
This error occurs when you dont start
your code in the proper directory in your program folder. So cd
navigate to the directory of your project and and run all the codes again.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.