overview ✨
- Mongo DB 사이트가기
- 회원 가입하기
- CLUSTER(클러스터) 만들기
- 몽고 DB 유저 생성 아이디 비밀번호 기억해야한다! 나중에 앱과 연결할 때 사용된다! ✨
- Mongoose 알아보기 간단하게 몽고 DB를 쓸 수 있는 Object Modeling Tool 이다.
① Create a New Cluster
클릭!
② 한국은 무료 TIER 가 없기 때문에, 가장 가까운 무료 TIER 국을 선택한다. → Singapore 🇸🇬
③ Cluster Tier 는 MO Sandbox
를 선택하면 된다.
④ Cluster Name 은 원하는것!
⑤ 생성이 되기까지 5분정도 시간이 걸린다. 🙂
① CONNECT
버튼을 누른다! → Connect your application
클릭!
② 복사해서 index.js
파일에 붙여넣는다. (아무 파일도 괜찮다.)
Replace <password> with the password for the sam user. Replace <dbname> with the name of the database that connections will use by default. Ensure any option params are URL encoded. 🚨
npm install mongoose --save
를 터미널에 입력해서 다운로드하기 💾
→ mongoose가 다운로드가 되면 package.json 의 dependencies 에도 한 줄 추가된다. 🙂
왜? → --save
를 붙였기 때문에 ㅎㅎ
👏🏻 가져온 모듈을 이용해서 텍스트
를 붙여넣는다. (아까 복사해왔던거! ... 밑에서 다시 코드 정리할거다)
🤚🏻 그리고 붙여넣은곳 뒤에 더 추가로 적어줘야 할 것들이 있다.
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
useFindAndModify: false
🤔 왜? 안써주면 에러들이 나기 때문에,,,,, 정확이 뭔지는 모르겠다.. ㅎㅎ 알아보기!!!
const mongoose = require("mongoose");
mongoose.connect(
"mongodb+srv://sam:123456789@cluster0.m9pmo.mongodb.net/Cluster0?retryWrites=true&w=majority", {
useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex: true, useFindAndModify: false
}
).then(() => console.log('MongoDB Connected...')) //🔥 연결이 잘 됐는지 확인하기
.catch(err => console.log(err)); //🔥 연결이 잘 안 된건지 확인하기
→ 성공 🙂