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);