User 모델 생성

이연중·2021년 4월 1일
0

Node.js

목록 보기
3/14

모델: 스키마를 감싸주는 역할

스키마: 데이터베이스 구조

models폴더 밑에 User.js파일 생성 후 아래 코드 작성

모델 생성 코드

const mongoose=require('mongoose');

//user에 관한 스키마 생성
const userSchema=moongoose.Schema({
   name:{
       type: String,
       maxlength: 50
   },
   email:{
       type:String,
       trim:true, //공백 없애주는 역할 ex)lee 12@naver.com에서 공백 제거해서 
       		   //					lee12@naver.com으로 만듦
       unique:1
   },
   password:{
       type:String,
       maxlength:5
   },
   lastname:{
       type:String,
       maxlength:50
   },
   role:{
       type:Number,
       default:0
   },
   image: String,
   token:{
       type:String
   },
   tokenExp:{ //토큰 유효기간
       type:Number
   }
});

//user 스키마를 모델로 감싸줌
const User=mongoose.model('User',userSchema);

module.exports={}
//다른 곳에서도 해당 모듈을 사용할 수 있음

참고

www.inflearn.com/course/따라하며-배우는-노드-리액트-기본

profile
Always's Archives

0개의 댓글