인프런 커뮤니티 질문&답변
글과 댓글 매칭 부분이 되지 않습니다. populate
작성
·
261
1
cat 대신하여 dog로 저는 따라 작성하였습니다.
docs 페이지에 정의 되어 있습니다.
postman으로 get 방식으로 dog/all로 호출 하였을때
comments schema가 등록이 안되었다고 되어 있는데 git 코드와 비교 해보면 다른점이 없어보여 질문드립니다.
출력해주는 에러에서는
[Nest] 26612 - 2021. 10. 15. 오후 3:33:29 ERROR [ExceptionsHandler] Schema hasn't been registered for model "comments". Use mongoose.model(name, schema)
export class DogRepository {
  constructor(@InjectModel(Dog.name) private readonly dogModel: Model<Dog>) {}
  async findAll() {
    console.log('findAll function');
    const CommentsModel = mongoose.model('comments', CommentsSchema);
    console.log(CommentsModel);
    const result = await this.dogModel
      .find()
      .populate('comments', CommentsModel);
    console.log(result);
    return result;
}
와 같이 추가되었습니다.
다만 populate이부분을 사용 안하면 정상 작동하나 두 collection의 join은 되지 않습니다.
혹시 에러 원인을 파악할수 있는 부분이나 제가 check해야될 부분이 있을까요??
다른기능은 정상 작용 중입니다.






.png?w=112)

스크린샷 다 찍었는데 빠져있네요 다시 질문드릴께요. ㅜ