๐ค ์ ํ์ํ๊ฐ?
- ํ์ ์ db server ๋ฅผ ๊ฐ๊ฐ์ ๊ฐ์ธ ์ปดํจํฐ ํ๊ฒฝ์์ ์คํํ๋ ค๋ฉด, mongodb ์ ํจ๊ป compass ๋ฑ์ ์ค์นํ๊ณ , ์ถ๊ฐ์ ์ธ ์ค์ ์ ํด์ผํ๋ฉด์ ์ฌ๋ฌ๊ฐ์ง ๊ท์ฐฎ์ ์ผ๋ ์๊ธฐ๊ณ , ๋ฒ์ ์ฐจ์ด๋ก ๋ํญ์ ๊ฒช์ ์๋ ์๋ค.
๐ข ์ต์ ์ฑ ์ธ๊ฐ?
- ์ต์ ์ฑ ์ ec2 ๋ฐฐํฌ๋ฅผ ํตํ์ฌ server ๋ฅผ ์ด์ด์ฃผ๋ ๊ฒ์ด์ง๋ง, ์ฐจ์ ์ฑ ์ผ๋ก ํ์๋ค์ ๋ฒ๊ฑฐ๋ก์ด ์ค์น ์์ด ๋น ๋ฅด๊ฒ ๊ฐ๋ฐ์ ์งํํ๊ธฐ์ํด ์ ํํ๊ธฐ์ ์ข์ ๋ฐฉ๋ฒ์ด ๋ ์ ์๋ค.
๐ต ์์
๐ฌ. MongoDB ์ค์ ํ์ผ์ ์์ ํ๋ค. (mongod.conf)
๊ฒฝ๋ก
- Linux : /etc/mongod.conf
- mac : /usr/local/etc/mongod.conf
- windows : c:/programFiles/mongoDB/Server/๋ฒ์ /bin/mongo.cfg
์ ์ฌํญ๋ค์ ๋๋ถ๋ถ์ ๊ฒฝ์ฐ์ด๋ฉฐ, ๋ฒ์ ๊ณผ ์ฌ์ฉ์ ์ค์ ์ ๋ฐ๋ผ ๊ฒฝ๋ก๊ฐ ๋ค๋ฅผ ์ ์๋ค.

๋ฉ๋ชจ์ฅ์ผ๋ก ์ด์ด๋ ์๊ด์๊ณ , vs code๋ก ์ด์ด๋ ์๊ด์๋ค.
net:
port: 27017
bindIp: 127.0.0.1
์์ ๊ฐ์ ์ฝ๋๊ฐ ์๋ ๊ณณ์ ์ฐพ์์ ์๋์ ๊ฐ์ด ์์ ํ๋ค.

๐ฌ ๋ฐฉํ๋ฒฝ ์ค์
MongoDB๊ฐ ์ฌ์ฉํ๋ ํฌํธ (default : 27017) ๋ฅผ ํ์ฉํ๋๋ก ์ค์ ํ๋ค.
- Linux (UFW): sudo ufw allow 27017
- macOS: ์์คํ ํ๊ฒฝ์ค์ > ๋ณด์ ๋ฐ ๊ฐ์ธ ์ ๋ณด ๋ณดํธ > ๋ฐฉํ๋ฒฝ > ๋ฐฉํ๋ฒฝ ์ต์ ์์ 27017 ํฌํธ๋ฅผ ํ์ฉํ๋๋ก ์ค์
- Windows: ์ ์ดํ > ์์คํ ๋ฐ ๋ณด์ > Windows Defender ๋ฐฉํ๋ฒฝ > ๊ณ ๊ธ ์ค์ > ์ธ๋ฐ์ด๋ ๊ท์น์์ ์ ๊ท์น์ ๋ง๋ค์ด 27017 ํฌํธ๋ฅผ ํ์ฉํ๋๋ก ์ค์
๐ฌ MongoDB ์ฌ์์
์ค์ ์ด ์ ์ฉ๋๋๋ก MongoDB๋ฅผ ์ฌ์์ํ๋ค.
- Linux: sudo systemctl restart mongod
- macOS: brew services restart mongodb-community (Homebrew๋ก ์ค์นํ ๊ฒฝ์ฐ)
- Windows: ์๋น์ค ๊ด๋ฆฌ์์์ MongoDB ์๋น์ค๋ฅผ ์ฐพ์ ์ฌ์์
๐ฃ ๋ค๋ฅธ ์ปดํจํฐ์์ ์ ์ํ๋ ๋ฐฉ๋ฒ
mongodb ์ ์ ์ํ ๋ uri ๋ฅผ ์ฌ์ฉํ๊ฒ ๋๋๋ฐ ๋ณดํต uri๋
- mongodb://127.0.0.1:27017/
- mongodb://localhost:27017/
์ด๋ฐ์์ผ๋ก ์ฌ์ฉํ๋ฉด local mongodb ๋ก ์ ์์ด ๊ฐ๋ฅํ๋ฐ ์๊ฒฉ์ผ๋ก ์ ์ํ๋ ค๋ฉด
const remoteIp = `๋ณธ์ธipv4address`;
const port = 27017;
const uri = `mongodb://${remoteIp}:${port}`;
uri๋ฅผ ์์ฒ๋ผ ์์ ํด์ฃผ๋ฉด mongodb์ ์ค์น, ๋ณ๋ค๋ฅธ ์ค์ ์์ด ์ ๊ทผ์ด ๊ฐ๋ฅํ๋ค.