我正在尝试根据我提供的价值提供其他服务ConfigService。
我遇到的问题是,在执行诸如findOne()(result is null)或countDocuments()(result is 0)之类的查询方法时,注入的猫鼬模型不会返回任何值。
我的服务类定义如下:
export class BaseService {
constructor(@InjectModel('Cat') public readonly catModel: Model<Cat>) {}
createService(option: string) {
if (option === 'OTHER') {
return new OtherService(this.catModel);
} else if (option === 'ANOTHER') {
return new AnotherService(this.catModel);
} else {
return new BaseService(this.catModel);
}
}
async findOne(id: string): Promise<Cat> {
return await this.catModel.findOne({_id: id});
}
async count(): Promise<number> {
return await this.catModel.countDocuments();
}
testClass() {
console.log('BASE SERVICE CLASS USED');
}
} …Run Code Online (Sandbox Code Playgroud)