컴퍼스


다운로드 버튼을 눌러주세요.


fill in connection fields individually를 클릭

위에서 connect를 누르시면 경고창이 하나 뜨는데 access 허용 누르시면 아래와 같이 뜹니다. 우리는 이미 실습을 꽤나 했기 때문에 우리가 실습한 내용이 모두 뜹니다.
여기서 CREATE DATABASE 눌러보세요.


2개의 항목을 입력하고 Create Datebase를 클릭해주세요.

testdb를 클릭하세요.

insert Document를 클릭하세요.

insert를 눌러서 데이터를 넣어주세요.

위와 같이 {}로 find를 해보세요.

마우스를 오버해보시면 여러가지 작업을 할 수 있다는 것을 알 수 있습니다.
클라우드
atlas라는 클라우드 서비스를 이용하여 구축해보도록 하겠습니다. 설치하는 것보다 쉽고 무료이니 한 번 이용해보시길 권해드립니다.

회원 가입 후 로그인을 해주세요.
회원 정책 동의 후 submit을 누르면 아래와 같이 작성하는 란이 나오는데 건너뛸 수 없으니 작성해주세요.


free Create 클릭하시면 됩니다.

무료버전에서는 한국을 선택할 수 없습니다. 일본 선택해주세요.
나머지 건너뛰시고 하단에 Create Cluster 클릭하시면 됩니다.

비밀번호 패스워드 설정합시다. 저희는 연습용이라 쉽게 작성하도록 하겠습니다.

순서대로 누르시면 됩니다. 현재 자신의 컴퓨터에서만 접속하게 하는 설정이에요. 다른 곳에서는 접속이 되지 않습니다.

여기서 connect를 누르면 됩니다.

connect your application을 클릭해주세요.

아래 코드 복사해 놓으면 준비 완료입니다.

저는 주소만 필요해서 체크박스 해제하고 주소만 가져왔어요.
mongodb+srv://hojun:<password>@cluster0.wkmnn.mongodb.net/myFirstDatabase?retryWrites=true&w=majority
index.js 파일입니다.
// npm init --yes // npm i express mongoose dotenv multer // npm install --save-dev nodemon // package.json에서 // "test": "echo \"Error: no test specified\" && exit 1"를 // "start" : "nodemon index.js"로 고치고 // npm start const express = require("express"); const app = express(); const dotenv = require("dotenv"); const mongoose = require("mongoose"); dotenv.config(); mongoose .connect(process.env.MONGO_URL, { useNewUrlParser: true, useUnifiedTopology: true, }) .then(console.log("DB 연결 완료!")) .catch((err) => console.log(err)); app.listen("8080", () => { console.log("노드 실행 중"); });
.env 파일입니다. <password> 부분은 여러분 비밀번호 넣어주세요.
MONGO_URL = mongodb+srv://hojun:<password>@cluster0.wkmnn.mongodb.net/myFirstDatabase?retryWrites=true&w=majority
MONGO_URL = mongodb+srv://hojun:hojun1234@cluster0.wkmnn.mongodb.net/myFirstDatabase?retryWrites=true&w=majority
실행시켰을 때 DB 연결완료가 뜨면 연결이 완료된 것입니다.
만약 CRUD가 발생하면 아래 Browse Collections에서 확인 가능합니다.

확인 값
