• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    미해결

cat repository에서의 오류

22.07.02 17:53 작성 조회수 441

0


async existsByEmail(email: string): Promise<boolean> {
try {
const result = await this.catModel.exists({ email });

return result;
} catch (error) {
throw new HttpException('db error', 400);
}
}

에서 return result부분에서 오류가 발생합니다.

src/cats/cats.repository.ts:20:7 - error TS2322: Type 'Pick<Document<Cat, any, any>, "_id">' is not assignable to type 'boolean'.

 

20       return result;

         ~~~~~~~~~~~~~~

exists() 따라가 보면 리턴타입이 boolean이 아닌거 같은데 어떤 부분을 확인해 보면 좋을까요?

 

console.log로 result를 찍어보면  { _id: new ObjectId~~~} 가 나옵니다.

답변 1

답변을 작성해보세요.

3

홍여진님의 프로필

홍여진

2022.07.04

exist() 가 버전업 되면서 {_id:...} 혹은 null을 리턴합니다. if(result) {return true} else {return false}로 바꿔주시면 됩니다.