• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    미해결

글과 댓글 매칭 부분이 되지 않습니다. populate

21.10.15 16:00 작성 조회수 140

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해야될 부분이 있을까요??

다른기능은 정상 작용 중입니다.

 

 

답변 2

·

답변을 작성해보세요.

1

안녕하세요! 

업로드된 질문에 코드가 잘 안보이는데 혹시 스크린샷으로 올려주실 수 있나요?

dydrms444님의 프로필

dydrms444

질문자

2021.10.18

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

0

dydrms444님의 프로필

dydrms444

질문자

2021.10.19

스크린샷 첨부하였습니다.~