โ๊ณต๋ถํ๊ฒ ๋ ๊ณ๊ธฐ
โก๏ธ ํ๊ต ์กธ์ ํ๋ก์ ํธ์์ NoSQL ์ ์ฌ์ฉํ๊ธฐ๋ก ํ์๊ณ , DB๋ก MongoDB ๋ฅผ ์ ํํ์๋ค. ์ปดํจํฐ์ MongoDB ๋ฅผ ์ค์นํ๊ณ , ๊ธฐ๋ณธ์ ์ธMongoDB ์ฉ์ด๋ฅผ ์ตํ๋ฉด์ Spring Boot ์ ์ฐ๋ํ์ฌ ์ฌ์ฉํ๋ ๊ณผ์ ๊น์ง ์ ๋ฆฌํด๋ณด๊ณ ์ ํ๋ค.
โก๏ธ MongoDB ์ค์น๋ ๊ณต์ ๋ ํผ๋ฐ์ค๋ฅผ ๋ณด๋ฉด์ ์งํํ์๊ณ , ์ฉ์ด ์ ๋ฆฌ์ Spring Boot ์ฐ๋์๋ ๊ณต์ ๋ ํผ๋ฐ์ค์ ๋๋ถ์ด ์ฌ๋ฌ ๋ธ๋ก๊ทธ๋ค์ ์ฐธ๊ณ ํ์๋ค.
๐ ์ฐธ๊ณ
Install MongoDB Community Edition on macOS — MongoDB Manual
Docs Home → MongoDB Manual MongoDB AtlasMongoDB Atlas is a hosted MongoDB service option in the cloud which requires no installation overhead and offers a free tier to get started.Use this tutorial to install MongoDB 6.0 Community Edition on macOS using
www.mongodb.com
โ๏ธ๊ณต๋ถํ ๋ด์ฉ
1๏ธโฃ MongoDB ์ค์น ์ ์ฒด ๋ช ๋ ์ด
โก๏ธ ํ๋ํ๋ ํ์ธ์ด ๊ท์ฐฎ์ผ๋ฉด ์๋ ๋ช ๋ น์ด๋ฅผ ์ญ ๋ฐ๋ผ์น๋ฉด ๋ฌด๋ํ๊ฒ ์ค์น ๊ฐ๋ฅํ๋ค.
# ์ค์น๋์ด ์์ง ์์ ๊ฒฝ์ฐ ์ค์น
xcode-select --install
# ์ด๋ฏธ mongodb ๊ฐ ์ค์น๋์ด์๋ ๊ฒฝ์ฐ์๋ ์๋ต ๊ฐ๋ฅ
brew tap mongodb/brew
# brew ์
๋ฐ์ดํธ
brew update
# mongodb ์ค์น (๋ฒ์ ์ ์์ ๋กญ๊ฒ)
# ์ค์น๋๋ ๋ชฉ๋ก : 1. server(mongod) 2. shared cluster(mongos) 3. DB shell(mongosh)
# ์์ฑํ๋ ํ์ผ/ํด๋ : 1. config ํ์ผ 2. log ํด๋ 3. data ํด๋
brew install mongodb-community@6.0
# MacOS ์์ mongodb์ ์ค์น ๊ฒฝ๋ก๋ฅผ ํ์ธํ๋ ๋ช
๋ น์ด
brew --prefix
# MongoDB ์คํ ๋ช
๋ น์ด (MacOs Service ๋ก ์คํ)
brew services start mongodb-community@6.0
# MongoDB ์คํ ํ์ธ ๋ช
๋ น์ด (MacOs Service ๋ก ์คํ ์)
# ์ ์ ์คํ ์ : mongodb-community started
brew services list
# MongoDB Shell ์ด๊ธฐ (๋จผ์ services start ๋ก ์คํํด์ฃผ์ด์ผํจ)
mongosh
2๏ธโฃ ์์ธ ๊ณผ์
โ xcode-select ์ค์น
# ์ค์น๋์ด ์์ง ์์ ๊ฒฝ์ฐ ์ค์น
xcode-select --install
โก๏ธ ๋งฅ CLI ๋ช ๋ น์ด ๋๊ตฌ๋ผ๊ณ ํ๋ค. ์ค์น๋์ด์์ง ์์ผ๋ฉด ์ค์นํ๊ณ ์์ํ๋ฉด ๋๋ค.
โก brew ๋ช ๋ น์ด๋ฅผ ํตํ MongoDB ์ ์ฅ์ ์์ฑ
# ์ด๋ฏธ mongodb ๊ฐ ์ค์น๋์ด์๋ ๊ฒฝ์ฐ์๋ ์๋ต ๊ฐ๋ฅ
brew tap mongodb/brew
# brew ์
๋ฐ์ดํธ
brew update
โก๏ธ brew tap ์ ๊ฒฝ์ฐ ํจํค์ง ์ ์ฅ์๋ฅผ ์์ฑํ๋ ๋ช
๋ น์ด์ด๋ค. ๋ง์ฝ MongoDB ๋ฅผ ์ฒ์ ์ค์นํ๋ ์ํฉ์ด๋ผ๋ฉด ํด๋น ๋ช
๋ น์ด๋ฅผ ํตํด ์ ์ฅ์๋ฅผ ๋ง๋ค์ด ์ฃผ์ด์ผํ๋ค.
โก๏ธ ์ ์ฅ์๋ฅผ ๋ง๋ค์ด ์ฃผ์์ผ๋ brew update ๋ฅผ ํตํด ์
๋ฐ์ดํธ ํด์ค๋ค.
โข brew ๋ช ๋ น์ด๋ฅผ ํตํ MongoDB ์ค์น
# mongodb ์ค์น (๋ฒ์ ์ ์์ ๋กญ๊ฒ)
brew install mongodb-community@(์ํ๋ ๋ฒ์ )
โก๏ธ ์ด์ ์ํ๋ ๋ฒ์ ์ผ๋ก ์ค์นํ๋ฉด๋๋ค. ๋งจ์ ์ฐธ๊ณ ๋์ ์๋ ๊ณต์ ๋ ํผ๋ฐ์ค๋ฅผ ๋ค์ด๊ฐ๋ฉด ๋ค์ํ ๋ฒ์ ์ผ๋ก ์ ํ์ด ๊ฐ๋ฅํ๋ค.

โก๏ธ ๋์ ๊ฒฝ์ฐ ์ค์นํ๋ ๊ณผ์ ์์ Xcode ๋ฒ์ ๊ด๋ จ ์๋ฌ๊ฐ ๋ฐ์ํ๋ค. ์ฑ์คํ ์ด์์ ์ ๋ฐ์ดํธ๋ฅผ ํ๋ฉด ์ฝ๊ฒ ํด๊ฒฐ๋์ง๋ง ๋ฌธ์ ๋ ์ ๋ฐ์ดํธ๊ฐ ์ค๋๊ฑธ๋ฆฐ๋ค. ์ ํ๋ธ ์ํ (๊ฒฐ๋งํฌํจ) ํ๋ ๋ณด๊ณ ์ค๋ฉด ๋์ถฉ ๋๋์์ผ๋ ์ฐธ๊ณ ํ๋๋ก ํ์.

# MacOS ์์ mongodb์ ์ค์น ๊ฒฝ๋ก๋ฅผ ํ์ธํ๋ ๋ช
๋ น์ด
brew --prefix
# MongoDB ์ค์น ํ์ธ
brew list
โก๏ธ ์ ๋ ๋ช ๋ น์ด๋ฅผ ํตํด ์ค์น ๊ฒฝ๋ก์ ์ค์น ์ฌ๋ถ ํ์ธ์ ํ ์ ์๋ค.
โฃ MongoDB ์คํ
# MongoDB ์คํ ๋ช
๋ น์ด (MacOs Service ๋ก ์คํ)
brew services start mongodb-community@(์ค์นํ ๋ฒ์ )
# MongoDB ์คํ ํ์ธ ๋ช
๋ น์ด (MacOs Service ๋ก ์คํ ์)
# ์ ์ ์คํ ์ : mongodb-community started
brew services list
โก๏ธ MongoDB ๋ฅผ ์คํ์์ผ์ฃผ๊ณ brew ๋ฅผ ํตํด ์๋น์ค ๋ชฉ๋ก์ ํ์ธํ๋ฉด ์คํ ์ฌ๋ถ๋ฅผ ํ์ธ ํ ์ ์๋ค.

โค MongoDB Shell ์ด๊ธฐ
# MongoDB Shell ์ด๊ธฐ (๋จผ์ services start ๋ก ์คํํด์ฃผ์ด์ผํจ)
mongosh
โก๏ธ ๊ณผ์ โฃ ์ ๋ช ๋ น์ด๋ฅผ ํตํด MongoDB ๋ฅผ ์ ์์ ์ผ๋ก ์คํํ์๋ค๋ฉด ์๋ ์ฌ์ง ์ฒ๋ผ ์ค์นํ ๋ฒ์ ์ด ๋ณด์ด๋ฉด์ ๋ฌธ์ ์์ด ๋ค์ด๊ฐ ์ ์๋ค.

โ๏ธ Compass ์๊ฐํ ๋๊ตฌ ์ค์น
โก๏ธ CLI ํ๋ฉด์ผ๋ก ๋ณด๊ธฐ ๋ฒ์ก์ค๋ฝ๋ค๋ฉด mongosh ์ ์ ๋์ ์์ฒด ์๊ฐํ ๋๊ตฌ์ธ Compass ๋ฅผ ํ์ฉํ๋ ๋ฐฉ๋ฒ๋ ์๋ค.
Try MongoDB Tools - Download Free Here
Free download for MongoDB tools to do more with your database. MongoDB Shell, Compass, CLI for Cloud, BI Connector and other database tools available.
www.mongodb.com


โก๏ธ ์ฌ์ฉํ๋ OS ๋ฅผ ์ ์ ํํด์ฃผ๊ณ ํ์ผ์ ๋ค์ด๋ฐ์ผ๋ฉด ๋ฐ๋ก ์ค์น๊ฐ๋ฅํ๋ค.


โก๏ธ ์์ ๊ณผ์ ์ ํตํด MongoDB ๊ฐ ์ ์ค์น๋์์ผ๋ฉด Connect ๋ก ์ ์ํ์ ๋ ์ ์์ ์ผ๋ก ํ๋ฉด์ด ์ ํ๋๋ค.
๐ง ๋ค์ ๋ด์ฉ
โก๏ธ ๋ค์์๋ MongoDB ์ ๋ํ ๊ฐ๋ตํ ๋ด์ฉ๊ณผ ํจ๊ป ๊ธฐ๋ณธ CRUD ๋ช ๋ น์ด์ ์ฌ์ฉ์ ์ถ๊ฐ ์ ๋๋ฅผ ๋ค๋ค๋ณผ ์์ ์ด๋ค.