지금까지 사용한 DBMS 는 MySql 밖에 없었는데 이번에는 NoSQL Database 중 가장 유명하고 사용률이 높은 Mongo DB DBMS 에 대해 포스팅을 하고자 한다.
MongoDB 는 C++로 작성된 오픈소스 문서지향 (Document-Oriented) 적 Cross-platform 데이터베이스이며, 뛰어난 확장성과 성능을 자랑한다.
NoSQL: Not Only SQL, 기존의 RDBMS 의 한계를 극복하기 위해 만들어진 새로운 형태의 데이터 저장소, 고정된 스키마 및 JOIN 이 존재하지 않는다.
Document: RDBMS 의 record 와 비슷한 개념, 데이터 구조는 한 개 이상의 key-value pair 로 이루어져있다.
Document 는 동적의 schema 를 가지고 있고, 같은 Collection 안에 있는 Document 끼리 다른 schema 를 갖고 있을 수 있다. 즉 서로 다른 데이터 (다른 key) 들을 가지고 있을 수 있다.
Collection: MongoDB Document 의 그룹, Document 들이 Collection 내부에 위치하고 있고, RDBMS 의 table 과 비슷한 개념으로 보면 되지만 schema 를 따로 가지고 있지는 않는다.
Database: Collection 들의 물리적인 컨테어니, 각 Database 는 파일시스템에 여러 파일들로 저장된다.
MongoDB 공식 다운로드 사이트 에서 각 OS 에 맞게 설치하면 된다.
윈도우 10 기준으로 설치를 진행했다.
.msi를 파일을 받아 설치를 시작한다.
Next > License Check & Next > Complete > Next > MongoDB Compass(MongoDB 관리를 위한 GUI 프로그램 - 본인은 해제 눌렀음.) > Next > Install > Finish
설치가 완료되면
이런식으로 설치 경로에 들어가 사진과 같이 보이는 bin 폴더 (설치 위치) 에 들어간다.
제어판 > 시스템 및 보안 > 시스템 > 고급 시스템 설정 > 고급 탭 > 환경 변수
시스템 변수에서 Path 를 찾아 편집 버튼을 누른다.
설치 경로/bin 을 Path 변수에 추가해줌. (새로 만들기 > 경로 복사 하면 된다.)
Powershell 또는 cmd 또는 WSL 을 실행해서 명령어 입력
PS C:\Program Files\MongoDB\Server\4.2\bin> cd 'C:\Program Files\MongoDB\Server\4.2\bin'
PS C:\Program Files\MongoDB\Server\4.2\bin> mongod
2020-07-13T15:44:45.578+0900 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2020-07-13T15:44:46.171+0900 W ASIO [main] No TransportLayer configured during NetworkInterface startup
2020-07-13T15:44:46.173+0900 I CONTROL [initandlisten] MongoDB starting : pid=9384 port=27017 dbpath=C:\data\db\ 64-bit host=BEOMS96
2020-07-13T15:44:46.173+0900 I CONTROL [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
2020-07-13T15:44:46.174+0900 I CONTROL [initandlisten] db version v4.2.8
2020-07-13T15:44:46.174+0900 I CONTROL [initandlisten] git version: 43d25964249164d76d5e04dd6cf38f6111e21f5f
2020-07-13T15:44:46.174+0900 I CONTROL [initandlisten] allocator: tcmalloc
2020-07-13T15:44:46.175+0900 I CONTROL [initandlisten] modules: none
2020-07-13T15:44:46.175+0900 I CONTROL [initandlisten] build environment:
2020-07-13T15:44:46.175+0900 I CONTROL [initandlisten] distmod: 2012plus
2020-07-13T15:44:46.175+0900 I CONTROL [initandlisten] distarch: x86_64
2020-07-13T15:44:46.175+0900 I CONTROL [initandlisten] target_arch: x86_64
2020-07-13T15:44:46.175+0900 I CONTROL [initandlisten] options: {}
2020-07-13T15:44:46.181+0900 I STORAGE [initandlisten] exception in initAndListen: NonExistentPath: Data directory C:\data\db\ not found. Create the missing directory or specify another path using (1) the --dbpath command line option, or (2) by adding the 'storage.dbPath' option in the configuration file., terminating
2020-07-13T15:44:46.181+0900 I NETWORK [initandlisten] shutdown: going to close listening sockets...
2020-07-13T15:44:46.185+0900 I - [initandlisten] Stopping further Flow Control ticket acquisitions.
2020-07-13T15:44:46.186+0900 I CONTROL [initandlisten] now exiting
2020-07-13T15:44:46.186+0900 I CONTROL [initandlisten] shutting down with code:100
2020-07-13T15:44:46.181+0900 I STORAGE [initandlisten] exception in initAndListen: NonExistentPath: Data directory C:\data\db\ not found. Create the missing directory or specify another path using (1) the --dbpath command line option, or (2) by adding the 'storage.dbPath' option in the configuration file., terminating
기본 디렉토리가 설정이 안되어 있어 나타나는 에러이므로 기본 디렉토리를 만들어 설정해주자.
mkdir C:\data\db
다시 서버를 실행한다.
서버 실행화면이다.
새 터미널을 열어서 클라이언트로 접속해보자
mongo
이상으로 mongoDB 에 대한 기본적인 설정을 끝냈다.
이후 포스팅
MongoDB 명령어 배우기
Mongoose, Express.js 를 활용한 MongoDB ORM 사용방법