mongodb로 댓글 대댓글 구현하기
조회수 902회
몽고디비로 댓글 대댓글 을 구현하려고 합니다.
스키마는
const replySchema = new Schema({
comment_id: Number,
creation_time: Number,
post_id: Number,
user: {
user_id: String,
loginType: String,
user_profile_img: String,
nick_name: String,
},
comment: String,
parents: Number,
});
const userSchema = new Schema({
user_id: String,
loginType: String,
user_profile_img: String,
nick_name: String,
});
const commentSchema = new Schema({
creation_time: Number,
post_id: Number,
user: userSchema,
comment: String,
children: [replySchema],
});
이렇게 되어 있습니다. 저게 comment라는 모델로 정의가 되어있는데 reply라는 모델로 따로 빼서 하는게 맞는 건지 아니면 저렇게 하나로 두고 하는 게 맞는건지 모르겠습니다. 댓글 추가는
const comment = new commentModel();
이렇게 모델을 가져와(?)
comment.create ({
---
})
이렇게 쓴다고 하면 대댓글은 코드를 어떻게 작성해야할까요..?
댓글 입력