인프런 커뮤니티 질문&답변
작성자 없음
작성자 정보가 삭제된 글입니다.
cat repository에서의 오류
작성
·
575
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~~~} 가 나옵니다.
퀴즈
민감한 데이터(예: 데이터베이스 URI)를 코드에 직접 노출하는 대신 권장되는 안전한 방법은 무엇일까요?
하드코딩하여 사용합니다.
환경 변수를 사용합니다.
주석으로 처리해둡니다.
별도의 파일에 확장자 없이 저장합니다.
답변 1
3
exist() 가 버전업 되면서 {_id:...} 혹은 null을 리턴합니다. if(result) {return true} else {return false}로 바꿔주시면 됩니다.





.png?w=112)