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

import mongoose from 'mongoose'

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

//형식을 정의함.
const UserSchema = new mongoose.Schema({
우지원's avatar
a    
우지원 committed
11
    username: {
우지원's avatar
우지원 committed
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
        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
32
33
34
35
    profileimg: {
        type: String
    },
}, {
우지원's avatar
우지원 committed
36
37
38
39
40
41
42
    //옵셥을 정의함.
    timestamps: true
    //기본이 false로 되어있음
    //user가 추가될때마다 createdAt(만들어진 시간 저장)과 updatedAt(수정될때 시간이 변경되어 저장)가 추가되어 시간을 저장함.
})

export default mongoose.models.User || mongoose.model('User', UserSchema)
43
//user라는 이름이 있으면 앞을 return하고 없으면 뒤를 실행함