📂 Archive/Web Programming

[MongoDB] User Model, User Schema

MIMDOING 2021. 5. 28. 00:50

우리가 웹 사이트 이용할 때 보통 회원가입을 하게 된다.

이름도 입력하고, 생년월일도 입력하고.. 웹사이트에서 요구하는 다양한 정보를 입력한다.

이런 정보들은 User Database에 들어가는데, 이렇게 유저와 관련된 데이터들을 보관하기 위해서

User Model(유저 모델), User Schema(유저 스키마) 를 간단히 알아보자!

User Model

Model은 Schema를 감싸주는 역할

Schema

const mongoose = require('mongoose')
const Schema = mongoose.Schema;
const bookSchema = mongoose.Schema({
    writer: {
        type: Schema.Types.ObjectId,
        ref: 'User'
    },
    title: {
        type: String,
        maxlength: 50
       },
    description: {
        type: String
   }
}, { timestamps: true})