For Programmer

2.몽고DB와 연결하기 - boiler-plate제작(backend) 본문

React & Node.js 프로젝트/boiler-plate 제작

2.몽고DB와 연결하기 - boiler-plate제작(backend)

유지광이 2020. 7. 31. 20:42
728x90

1.몽고 DB Cluster 생성하기

* 회원 가입 후 cluster 무료버젼을 생성하면 된다. aws-singapore 선택(영상참고)

2.몽고DB 사용자계정 만들고 세팅하기

3. 노드js에서 몽구스 모듈 다운받기

 

4. 몽구스 모듈을 import한 후에 몽구스 사용자계정 설정하기

5. 몽고DB 'user' collection 만들어보기(models-User.js)

const mongoose = require("mongoose");
const userSchema = mongoose.Schema({
  name: {
    type: String,
    maxlength: 50,
  },
  email: {
    type: String,
    trim: true, //공백제거
    unique: 1, //unique함(중복x)
  },
  password: {
    type: String,
    minlength: 5,
  },
  lastname: {
    type: String,
    maxlength: 50,
  },
  role: {
    type: Number,
    default: 0,
  },
  image: String,
  token: {
    type: String, //유효성관리
  },
  tokenExp: {
    type: Number, //유효기간관리
  },
});
onst User = mongoose.model("User", userSchema); //1st모델의이름,2nd데이터

module.exports = User; //다른파일에서사용가능

 

*해당강의

 

 

728x90
Comments