강의

멘토링

커뮤니티

Inflearn Community Q&A

saltcoffee's profile image
saltcoffee

asked

Solid backend NestJS, from basics to advanced

Cat-to-cat communication API (comments, likes) - Service completed

populate 문제(cats schema 오류) 해결법

Written on

·

983

14

강의대로 따라 했으나, 아래와같은 오류 나는경우 해결법 입니다.

ERROR [ExceptionsHandler] Schema hasn't been registered for model "comments".

Use mongoose.model(name, schema)

다른 문의글 보면 답변으로 버전 문제라고 버전을 내리라고 하시는데 , 좀 이상한 답변이라는 생각에

진짜 몇시간동안 헤매다가 해결했습니다.

 

현재기준 최신버전

"@nestjs/common": "^9.0.0",
"@nestjs/mongoose": "^9.2.1",
"mongoose": "^6.9.0",

에서 아래와 같이 해결 했습니다. 주석참조.

export class CatsRepository {
  constructor(
    @InjectModel(Cat.name) private readonly catModel: Model<Cat>,
    // 해당 라인 추가, 참고로 강의에선 Comments 인데 저는 Cat과 같이 단수형으로 만들어서 Comment 입니다.
    @InjectModel(Comment.name) private readonly commentModel: Model<Comment>,
  ) {}

  async findAll() {
    const result = await this.catModel
      .find()
      // populate 파라미터 변경
      .populate({ path: 'comments', model: this.commentModel });

    return result;
  }
...
}

화면 캡처 2023-02-01 171223.png

다른 누군가에게 도움이 되기를

 

node.jsNestJSssrexpressnestjsnodejsmongodb

Answer 6

0

강의 계속 다시 들어도 못찾겠어서 포기할려다가 이 글 보고 해결했습니다.

0

도움이 되었습니다 👍👍👍

0

감사합니다!

0

저의 구세주십니다.. 감사합니다.

0

와.. 버전을 아무리 바꿔도 안되길래 포기하던 찰나, 위의 방법으로 해결했네요 감사합니다! :)

0

덕분에 문제 해결했습니다! 감사합니다!

saltcoffee's profile image
saltcoffee

asked

Ask a question