npm install mongoose --save
Model : schema를 감싸주는 역할
Schema : 하나하나의 정보를 지정하는 역할
const mongoose = require('mongoose');
// schema 생성
const userSchema = mongoose.Schema({
name :{
type: String,
maxlength: 50
},
email :{
type: String,
trim: true, // 여백공간 없애주는 역할
unique: 1
},
password :{
type: String,
minlength: 5
},
lastname :{
type: String,
maxlength: 50
},
role :{
type: Number,
default: 0
},
image: String,
token :{ // 유효성 검사
type: String
},
tokenExp :{ // 유효기간
type: Number
},
})
// 스키마를 모델로 감싸준다
const User = mongoose.model('User', userSchema)
module.exports = { User }