Err: Nest can't resolve dependencies of the TrackerService (?). Please make sure that the argument DriverModel at index [0] is available in the AppModule context. enter image description here Potential solutions:
- If DriverModel is a provider, is it part of the current AppModule?
- If DriverModel is exported from a separate @Module, is that module imported within AppModule? @Module({ imports: [ /* the Module containing DriverModel */ ]
app.module
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { AppGateway } from './app.gateway';
import { TrackerModule } from './tracker/tracker.module';
import { MongooseModule } from '@nestjs/mongoose';
@Module({
imports: [TrackerModule,MongooseModule.forRoot('mongodb://127.0.0.1:27017/tracker')],
controllers: [AppController],
providers: [AppGateway,AppService],
})
export class AppModule {}
'
tracker.module
import { Module } from '@nestjs/common';
import { TrackerService } from './tracker.service';
import { MongooseModule } from '@nestjs/mongoose';
import { DriverSchema } from './schemas/driver.schema';
@Module({
imports: [MongooseModule.forFeature([{ name :'Driver', schema: DriverSchema }])],
controllers: [],
providers: [TrackerService]
})
export class TrackerModule {}
tracker.service
import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Driver } from './interfaces/driver.interface';
import { Model } from 'mongoose';
import { driverDto } from './dtos/driver.dto';
@Injectable()
export class TrackerService {
constructor(@InjectModel('Driver') private driverModel: Model<Driver>){}
addDriver( driverDTO: driverDto): Promise<Driver>{
const newDriver = new this.driverModel(driverDTO);
return newDriver.save();
}
}