Programming/React+Node
따라하며 배우는 노드, 리액트 시리즈 - 기본 강의 #4 MongoDB Model & Schema
히욤이
2021. 8. 12. 21:32
User Schema 생성
- Model : Schema를 감싸주는 역할
1. models 폴더 생성
C:\react-node\boiler-plate> mkdir models
2. User 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 :50
},
role : {
type : Number,
default : 0
},
image : String,
token : {
type : String
},
tokenExp : {
type : Number
}
})
const User = moongoose.model('User',userSchema); //schema를 model로 감싸줌
module.exports = { User }; //다른 곳에서도 쓸 수 있게 exports 해줌