리액트- #4 MongoDB Model & Schema

Jeongwon·2022년 1월 20일
0

리액트

목록 보기
3/6

1) Model

  • Schema를 감싸주는 역할

2) Schema

  • 정보들...
const mongoose = require('mongoose');

const UserSchema = mongoose.Schema({
    name: {
        type: String,
        maxlength: 50
    },
    email: {
        type: String, 
        trim: true, //space를 없애주는 역할
        unique: 1 //똑같은 이메일이 없게
    },
    password: {
        type: String,
        minlength: 5
    },
    lastname: {
        type: String,
        maxlength: 50
    },
    role: { //관리자인지 일반유저인지
        type: Number, //0은 일반유저로 지정하고 싶음(다른 숫자는 다른 역할)
        default: 0 //기본값은 0(일반유저)
    },
    image: String,
    token: {
        type: String
    },
    tokenExp: {
        type: Number
    }
})

const User = mongoose.model('User', UserSchema) //schema를 model로 감쌈

module.exports = {User} //이 모델을 다른 파일에서도 쓸 수 있게 export
profile
(❁´◡`❁)

0개의 댓글

관련 채용 정보