일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
31 |
- UIKit
- ViewBuilder
- 클린코드
- 스유
- 초보iOS개발자
- Postman
- Swift알고리즘
- github
- 수정중
- SwiftUI
- 유데미
- 글또
- ios
- Swift
- 글또10기
- 개발회고
- 글또9기
- 12회차
- 개인앱
- 리액트입문
- 글또x코드트리
- 알고리즘
- RxSwift
- 글쓰기
- 회고
- JavaScript
- 비동기
- 왕초보
- iOS개발
- git
- Today
- Total
playground_avec coding
[Node.js] Mongo DB 연결하기 본문
저번에 작성한 boiler-plate 라는 폴더에 mongo DB 연결 하는 방법
The most popular database for modern apps
We're the creators of MongoDB, the most popular database for modern apps, and MongoDB Atlas, the global cloud database on AWS, Azure, and GCP. Easily organize, use, and enrich data — in real time, anywhere.
www.mongodb.com
1. 회원가입
2. cluster(클러스터) 생성
- cluster 생성
- 1. IP address 만들어라
- 2. Database User 의 ID 와 PW 를 만들어라
- 3. choose a connection method
- 4. Connect your application
- 5. Add your connection string into your application code
copy 하고 pw 를 쳐준다.
3. Mongo DB 유저 생성.
4. Mongoose 설치.
Node.js 를 설치하였으면 vscode 터미널 창에서
npm install mongoose --save 명령어를 친 후 로딩 다 된후에
package.json 에 dependencies 에
"mongoose": "^5.12.11" 가 뜬 것을 확인 할 수 있다.
Mongo DB 를 편하게 쓸 수 있는 object Modeling Tool 이다
app 에 MongoDB 연결
index.js 에서
const mongoose = require ('mongoose')
mongoose.connect('mongodb+srv://나의Database user명:password@cluster0.bnqwd.mongodb.net/myFirstDatabase?retryWrites=true&w=majority\
',{
useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex: true, useFindAndModify: false
}).then(() => console.log('MongoDB connected...'))
.catch(err =>console.log(err))
연결되면 'MongoDB connected...' 으로 터미널 창에서 나오게 자바스크립트(ES6) 코드를 쳐 준다.
그 외 오류방지를 위해 useNewUrlParser, useUnifiedTopology,useCreateIndex,useFindAndModify 라고 설정해준다.
.catch( err => console.log(err) ) 에러가 뜨면 catch 구문으로 err 이라고 뜨게 쳐준다.
'front-end > node.js' 카테고리의 다른 글
기밀 정보를 보호하는 방법 2가지 (0) | 2021.06.09 |
---|---|
[node mon] 설치하기 (0) | 2021.06.08 |
[client -server 테스트] Body-parser와 Postman 이용 (0) | 2021.06.08 |
[Mongo DB] 에서의 Model 과 Schema 의 개념, 역할 (0) | 2021.06.02 |
Node.js 와 Express.js 다운로드 받기 (0) | 2021.05.27 |