-
Model, Schema 설정Study/Node, React 기초 강의_John Ahn 2023. 2. 12. 12:50
Model이란?
Schema를 감싸주는 역할이다.
Schema란?
하나하나의 정보를 지정해 줄 수 있는 것이다.
User.js 생성
프로젝트에 models라는 이름의 폴더를 만들고 User.js라는 파일을 생성한다.
// mongoose를 요청함 const mongoose = require('mongoose'); // Schema 설정 const userSchema = mongoose.Schema({ name: { type: String, maxlength: 50 }, email: { type: String, trim: true, unique: 1 }, password: { type: String, minlength: 5 }, lastname: { tpye: String, maxlength: 50 }, role: { type: Number, default: 0 }, image: String, token: { type: String }, tokenExp: { type: Number } }) // Schema를 모듈로 감싸 줌 const User = mongoose.model('User', userSchema) // 모듈을 다른 곳에서도 사용할 수 있도록 하는 코드 module.exports = {User}
'Study > Node, React 기초 강의_John Ahn' 카테고리의 다른 글
BodyParser & PostMan & 회원 가입 기능 (0) 2023.02.13 SSH를 이용하여 GITHUB 연결 (0) 2023.02.13 Git과 Visual Studio 연동 (0) 2023.02.13 Mongo DB 연결 (0) 2023.02.11 개발 환경 설치_Node.js, express js, Visual Studio (Window) (0) 2023.02.11