#4 MongoDB Model & Schema
2022. 8. 3. 13:54ㆍTIL/따라하며 배우는 노드 리액트
728x90
[인프런] 따라하며 배우는 노드, 리액트 시리즈 - 기본강의를 들으며 정리한 내용입니다.
Model : Schema를 감싸주는 역할
Schema: 상품에 비유했을 때 상품의 이름, 가격, 정보 등을 작성하는 것을 의미한다.
- models 폴더 생성하기
- 폴더 내부에 User.js 파일 생성하기
- User.js 파일 내부에 코드 작성하기
const mongoose = require('mongoose');
const userSchema = mongoose.Schema({
name: {
type: String,
maxlength: 50,
},
email: {
type: String,
trim: true, //문자열의 공백을 제거해주는 역할
unique: 1
},
password: {
type: String,
minlength: 5,
},
lastname: {
type: String,
manlength: 50,
},
role: {
type: Number,
default: 0
},
image: String,
token: {
type: String
},
tokenExp: {
type: Number
}
})
const User = mongoose.model('User', userSchema)
module.exports = {User}
'TIL > 따라하며 배우는 노드 리액트' 카테고리의 다른 글
#8 Nodemon 설치 (0) | 2022.08.03 |
---|---|
#7 BodyParser & PostMan & 회원 가입 기능 (0) | 2022.08.03 |
#5 Git 설치 / #6 SSH를 이용해 GITHUB 연결하기 (0) | 2022.08.03 |
#3 몽고 DB 연결 (0) | 2022.08.03 |
#2 NODE JS와 EXPRESS JS 다운로드 하기 (0) | 2022.08.03 |