User.js 1.06 KB
Newer Older
우지원's avatar
우지원 committed
1
2
3
4
//주고받는 형식을 정의함.

import mongoose from 'mongoose'

5
const { String } = mongoose.Schema.Types
JeongYeonwoo's avatar
JeongYeonwoo committed
6
const { Array } = mongoose.Schema.Types
우지원's avatar
우지원 committed
7
8
9
10
11
//원래 java의 string이 아니라 mongoose의 string을 쓰기 위해 불러옴.
//object의 id를 쓸때에도 추가시켜줘야됨.

//형식을 정의함.
const UserSchema = new mongoose.Schema({
우지원's avatar
a    
우지원 committed
12
    username: {
우지원's avatar
우지원 committed
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
        type: String,
        required: true,
    },
    nickname: {
        type: String,
        required: true,
    },
    email: {
        type: String,
        required: true,
        unique: true,
        //unique: 같은 email을 두번넣으면 error발생함
    },
    password: {
        type: String,
        required: true,
        select: false,
        //정보를 찾을때 찾지 않게함
        //플러스 옵션을 주면 찾을 수 있음(mongoose에서 용법찾아봐야됨)
    },
JeongYeonwoo's avatar
JeongYeonwoo committed
33
    profileimg: {
JeongYeonwoo's avatar
JeongYeonwoo committed
34
        type: String,
JeongYeonwoo's avatar
JeongYeonwoo committed
35
        default: '3cd14b9bcb2007f324fcb82e0b566cce',
JeongYeonwoo's avatar
JeongYeonwoo committed
36
37
    },
}, {
Choi Ga Young's avatar
Choi Ga Young committed
38
   
우지원's avatar
우지원 committed
39
    timestamps: true
Choi Ga Young's avatar
Choi Ga Young committed
40
   
우지원's avatar
우지원 committed
41
42
43
})

export default mongoose.models.User || mongoose.model('User', UserSchema)
Choi Ga Young's avatar
Choi Ga Young committed
44