티스토리 뷰

1. 스키마(Schemas) 란 ?

데이터를 매핑하는데 사용되는 하나하나의 정보를 지정해 주는 역할을 합니다.  스키마에서 알 수 있는 정보는 데이터의 형식, 최소 길이, 최대 길이, 공백 등등 데이터의 정보를 알 수 있습니다. 

const userSchema = mongoose.Schema({
    name :{
            type : String,
            maxlength : 50
    },
    email : {
            type: String,
            trim: true,
            unique :1
    },
    password : {
        type: String,
        maxlength : 70
    },
    lastname : {
        type: String,
        maxlength:50
    },
    role : {
        type : Number,
        default : 0
    },
    image : String,
    token : {
        type: String
    },
    //토큰을 이용해서 유효성을 관리 
    tokenExp : {
        type : Number 
    }
    //유효기간, 토큰이 사용할 수 있는 기간을 주는 것 

})

 

 

2. Model 이란 ?

스키마를 감싸는 역할을 합니다. 

index.js 에서 사용할 수 있게 export 시켜줍니다.

const User = mongoose.model('User', userSchema )
module.exports = {User}

 

 

https://mongoosejs.com/docs/guide.html#schemas

 

Mongoose v6.9.0: Schemas

If you haven't yet done so, please take a minute to read the quickstart to get an idea of how Mongoose works. If you are migrating from 5.x to 6.x please take a moment to read the migration guide. Everything in Mongoose starts with a Schema. Each schema ma

mongoosejs.com


DB , 데이터 베이스 누군가 얘기했을 때 알아 들을 수 있게 개념은 알아두도록 하자!  

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2026/04   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30
글 보관함