1. 구름 IDE에서 설치하기
클라우드 환경에서 MongoDB를 사용하는 방법에 대해 알아보겠습니다.
- 구름 IDE 접속 후 로그인을 합니다.
- 콘솔로 가기를 클릭합니다.

- 새 컨테이너를 생성을 클릭합니다.

- 컨테이너의 이름과 설명을 입력합니다.

- 소프트웨어 스택은 Node.js로 하시고, MongoDB 설치를 클릭한 후 생성하기 버튼을 누릅니다.

컨테이너 생성이 완료되었으면 컨테이너 실행하기를 클릭합니다.

MongoDB를 설치하기 위해 터미널 창을 열도록 하겠습니다. Alt+Shift+T를 누르면 새 터미널 창을 열 수 있습니다.
터미널에 아래와 같은 코드를 ctrl+shift+V를 눌러 복사 붙여넣기를 합니다.
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4 && (echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/4.0 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-4.0.list) && apt-get update && apt-get install -y mongodb-org && mkdir -p /data/db

이후 mongod를 입력하여 MongoDB의 서버를 키도록 하겠습니다.
mongod

MongoDB의 클라이언트와 연결하기 위해 새 터미널 창을 하나 더 켠 후, mongo를 입력합니다.
mongo

이렇게 mongo쉘에서 입력한 명령어는 MongoDB 서버로 보내집니다. 이렇게 구름 IDE에서 MongoDB 설치를 완료했습니다.
2. 로컬에서 Mongo DB 설치
2-1. Windows 10 이전
MongoDB 다운로드 센터 에서 바이너리를 다운로드합니다 .
MongoDB 다운로드 센터에 들어가 버전을 선택하여 다운로드를 진행합니다.

설치 파일을 실행한 후 NEXT를 클릭합니다.

라이선스에 동의를 한 후 NEXT를 클릭합니다.

Setup Type을 선택하라 나오는데 다른 경로를 변경할 경우에 Custom을 클릭하여 진행하고 기본 경로로 모든 기능이 포함된 상태로 설치를 원하시는 경우에는 Complete를 클릭합니다.

기본 설정으로 Dara Directory와 LogDirectory를 변경할 수 있으며 경로 변경이 없을 시 NEXT를 클릭합니다.

MongoDB Compass Install에 체크한 후, NEXT를 눌러 진행합니다.


Windows 탐색기를 클릭하고 OK를 누르면 설치를 완료되었다고 나타납니다. 이후, 컴퓨터를 재시작합니다.

MongoDB 환경 변수 설정을 위해 시스템 환경 변수 편집을 클릭합니다.

고급 > 환경변수 클릭한 후, 시스템 변수의 Path를 클릭합니다.


클릭하면 환경 변수를 추가할 수 있습니다. 설치된 MongoDB의 bin폴더 경로를 입력하여 환경 변수에 추가한 후 확인을 클릭합니다. (폴더를 꼭 확인해보세요. version이 조금 다를 수 있습니다!)
C:\Program Files\MongoDB\Server\5.0\bin

설정 완료되면 확인을 클릭하여 저장합니다.


C:\\data\\db 폴더를 만들어줍니다. 그 후에 cmd를 실행해 mongod 를 입력해봅니다.

localhost:27017 을 브라우저에 실행해서 아래와 같이 나온다면 설치가 정상적으로 완료된 것 입니다.

2-2. Windows 10
Chocolatey는 Windoiws 유저를 위한 패키지 매니저 입니다. Windows 10 이전 버전 다운로드 방식과 달리 MongoDB를 쉽게 설치할 수 있습니다.
- Chocolatey를 설치하기 위해, Windows powershell 관리자 권한으로 열어 아래의 명령어를 입력한 후 Enter을 칩니다.
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
- 설치가 잘 되었는지 확인하기 위해 choco라고 입력합니다.
choco

- 마지막으로 MongoDB를 설치하도록 하겠습니다. ‘Do you want to run the script?’라는 질문이 뜨면 Y를 입력해주세요.
choco install mongodb
2-3. MacOS
- 터미널 창을 열고 아래의 코드를 복사 붙여넣기 해 homebrew를 설치합니다.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
에러 메시지가 뜬다면 아래의 코드를 입력합니다.
x
- homebrew 설치가 완료되었으면 mongodb를 설치하도록 하겠습니다.
brew tap mongodb/brew brew install mongodb-community@5.0
- mongodb 실행을 해보도록 하겠습니다.
brew services start mongodb-community@5.0
2-4. 설치 확인
설치가 잘 되었는지 확인하기 위해서 터미널 창에서 아래의 명령어를 입력합니다. 아래 명령어가 제대로 실행이 안된다면 위로 올라가 환경설정을 해주세요.
mongod

만약, command not found라고 나오면 설치가 되지 않은 상태입니다.

접속확인 주소
http://localhost:27017/
M1 맥북은 아래 포스팅을 확인해주세요.