본문 바로가기

데이터베이스3

[Node.js] Passport 모듈을 이용한 로그인 구현 1 - 모듈 설치 / 준비 Node.js 모듈 중에는 Passport라는 모듈이 있습니다. 이 모듈을 사용하면 로그인 시에 인증을 보다 쉽게 구현할 수 있습니다. 프로젝트를 다음과 같이 구성합니다. 코드를 다음과 같이 입력합니다. /models/User.js const mongoose = require('mongoose'); const Schema = mongoose.Schema; // create schema const UserSchema = new Schema({ email: { type: String, required: true }, password: { type: String, required: true }, name: { type: String, required: true } }); module.exports = User.. 2019. 1. 29.
[ Node.js ] mLab을 이용한 MongoDB 연결 3 - CRUD 구현 (2) UPDATE 동작은 CREATE 동작의 코드를 수정함으로써 구현할 수 있습니다. 수정된 app.post()코드는 아래와 같습니다. app.post('/', (req, res) => { const studentFields = {}; if (req.body.name) studentFields.name = req.body.name; if (req.body.score) studentFields.score = req.body.score; Student.findOne({ name: req.body.name }).then(student => { if (student) { Student.findOneAndUpdate({ name: req.body.name }, { $set: studentFields }, { new: .. 2019. 1. 29.
[ Node.js ] mLab을 이용한 MongoDB 연결 - CRUD 구현 (1) 이전 포스트 보러가기 [Node.js] mLab을 이용한 MongoDB 연결 1 mLab 바로 가기 MongoDB Atlas Database | Multi-Cloud Database Service The multi-cloud database service at the heart of our developer data platform that accelerates and simplifies how you build with.. futuregate.tistory.com 이전 포스트 내용을 모르시는 분들은 위의 링크로 가셔서 보고 오시길 바랍니다. 이어서 작성하겠습니다. ㅎㅎ 다음으로, 데이터베이스에서 사용할 '모델'이 필요합니다. MySQL에서는 '테이블' 개념과 비슷하다고 볼 수 있습니다. 여기서는 학생에.. 2019. 1. 28.