-
카테고리
-
세부 분야
백엔드
-
해결 여부
미해결
글과 댓글 매칭 부분이 되지 않습니다. 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해야될 부분이 있을까요??
다른기능은 정상 작용 중입니다.
답변을 작성해보세요.
1
0
답변 2