Id 자동 카운팅

leehowook·2022년 8월 30일
0

routes

const maxCommentId = await Comment.findOne().sort("-commentId").exec()
let commentId = 1
if (maxCommentId) {
    commentId = maxCommentId.commentId +1
}

or

model
AutoIncrement

studySchema.plugin(AutoIncrement, { inc_field: 'roomId' });
const Room = mongoose.model('Room', studySchema);
profile
be higher

0개의 댓글