Nest can't resolve dependencies of the ProductModel (?)

Viewed 214

I am trying to implement Mongoose crud service. I am missing something on injecting model or injecting module.

I am getting below error:

Nest can't resolve dependencies of the ProductModel (?). Please make sure that the argument DatabaseConnection at index [0] is available in the MongooseModule context

app.module.ts

@Module({
  imports: [ProductsModule,
    MongooseModule.forRoot(config.mongoURI)],
})
export class AppModule { }

product.module.ts

@Module({
  imports: [MongooseModule.forFeature([{ name: 'MyProduct', schema: ProductSchema }])],
  controllers: [ProductsController],
  providers: [ProductsService],
  exports: [ProductsService]
})
export class ProductsModule { }

product.service.ts

@Injectable()
export class ProductsService extends GenericMongooseCrudService<IProduct> {
  eventEmitter: EventEmitter = new EventEmitter();
  @InjectModel('MyProduct') private readonly userModel: Model<IProductModel>;
}

product.interface.ts

export interface IProduct extends IModelInstance {
  value: string
}

export interface IProductModel extends IProduct, IMongoDocument {
}
0 Answers
Related