PlayData

[MongoDB] Mac์—์„œ mongo DB ์„ค์น˜ํ•˜๊ธฐ(Monterey)

๊น€์œ ๋‹ˆ์ฝ˜ 2022. 1. 13. 20:29

์ฐฉ์‹คํ•˜๊ฒŒ OS ์—…๋Žƒ์„ ๋„ˆ๋ฌด ์ž˜ํ•œ ํƒ“์— ๊ณ ์ƒํ•ด๋ฒ„๋ฆฐ ๋ชฝ๊ณ DB ์„ค์น˜๊ธฐ

 

Mongo DB ๋ฅผ ๋งฅ์—์„œ ์„ค์น˜ํ•˜๊ธฐ 

1. HomeBrew Tap ๋“ฑ๋ก

brew tap mongodb/brew

2. MongoDB ์„ค์น˜

brew install mongodb-community

 

3. /data/db ํด๋” ๋งŒ๋“ค๊ธฐ

$ sudo mkdir -p data/db
$ sude chown {username}/data/db

๋Œ€๋ถ€๋ถ„ ๊ตฌ๊ธ€๋งํ•ด์„œ ๋‚˜์˜จ ๋ฐฉ๋ฒ•๋“ค์ด ์œ„ ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•˜๋ผ๊ณ  ํ•˜๋ผ๊ณ  ๋˜์–ด์žˆ๋Š”๋ฐ, ์•„๋ฌด๋ฆฌ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•ด๋„ ๋ญ๊ฐ€ ์ƒ์„ฑ๋˜์ง€ ์•Š์•˜๋‹ค. 

ํ•œ์ฐธ ๊ฒ€์ƒ‰ ํ›„ ๋งฅ OS ๊ฐ€ Catalina ์ดํ›„์˜ OS๋Š” root ํด๋”์—์„œ read-only์—ฌ์„œ ํด๋”๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์—†๋‹ค๊ณ  ํ•œ๋‹ค.  

์• ํ”Œ์ด ๋„ˆ ์—…๋Žƒํ• ๋ž˜?๋ผ๊ณ  ํ•˜๋ฉด ๋˜ ์ฐฉ์‹คํ•˜๊ฒŒ ๋งค๋ฒˆ ์—…๋ฐ์ดํŠธ ํ•˜๋Š” ๋‚˜๋Š” ๋„ˆ๋ฌด ์ตœ๊ทผ์ด๋ผ ๊ตฌ๊ธ€๋ง ์ •๋ณด๋„ ๋ณ„๋กœ ์—†๋Š” Monterey ๋ฒ„์ „์ด์—ˆ๊ณ ...

 

$ mongo

 

๋ฅผ ์‹คํ–‰ํ•˜๋‹ˆ ์•„๋ž˜์˜ ์—๋Ÿฌ๊ฐ€ ๋‚˜์„œ ๋˜ ํ•œ์ฐธ ํ—ค๋งธ๋‹ค. 

MongoDB shell version v5.0.5
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect@src/mongo/shell/mongo.js:372:17

 

๊ฒฐ๊ตญ ์‚ฌ์šฉ์ž ํด๋” ํ•˜์œ„์— ์ง์ ‘ dataํด๋”๋ฅผ ๋งŒ๋“ค๊ณ , data ํ•˜์œ„์— db ํด๋”๋ฅผ ๋งŒ๋“ค์—ˆ๋‹ค. 

๊ทธ๋ฆฌ๊ณ  dbpath๋ฅผ ๋‹ค์‹œ ์„ค์ •ํ•ด์คŒ 

 

 

4. ํ„ฐ๋ฏธ๋„๋กœ ์„ค์ •

zsh๋ฅผ ์‚ฌ์šฉํ•˜๋ฏ€๋กœ, 

ํ„ฐ๋ฏธ๋„ ์ฐฝ์— 

% vi ~/.zshrc

๋ฅผ ์ž…๋ ฅํ•œ๋‹ค.

 

i๋ฅผ ๋ˆŒ๋Ÿฌ ์ˆ˜์ •๋ชจ๋“œ๋กœ ๋“ค์–ด๊ฐ„ ํ›„ 

 

export MONGO_PATH=/usr/local/mongodb
export PATH=$PATH:$MONGO_PATH/bin

๋ฅผ ์ž…๋ ฅํ•œ๋‹ค.

๊ทธ๋ฆฌ๊ณ  ์—”ํ„ฐ๋ฅผ ๋ˆ„๋ฅด๊ณ  :wq ๋ฅผ ์“ฐ๊ณ  ๋ˆŒ๋Ÿฌ ์ˆ˜์ • ์ €์žฅ ํ›„ ์ข…๋ฃŒ๋ฅผ ํ•œ๋‹ค.

 

๊ทธ๋ฆฌ๊ณ !

 

5. path ์„ค์ •

ํ„ฐ๋ฏธ๋„์—์„œ path์„ค์ •์„ ๋‹ค์‹œํ•ด์ค€๋‹ค.

์—ฌ๊ธฐ์„œ๋„ ๋˜ ํ•œ์ฐธ ์• ๋ฅผ ๋จน์—ˆ๋‹ค

์‚ฌ์šฉ์ž๋ช…์—๋Š” ๋ณธ์ธ์ด ์‚ฌ์šฉํ•˜๋Š” user ํด๋”๋ช…์„ ์“ฐ๋ฉด ๋œ๋‹ค!

mongod --dbpath {์‚ฌ์šฉ์ž๋ช…}/data/db

 

๋....!!

 

?? ๊ทธ๋Ÿฐ๋ฐ ๋งค ๋ฒˆ ๊ปํ‚คํ•  ๋•Œ๋งˆ๋‹ค db path๋ฅผ ์ƒˆ๋กœ ์„ค์ •ํ•ด์•ผํ•˜๋‚˜๋ณด๋‹ค.. ๋ ๋กœ๋ฆฌ

 

 

 

๋„์™€์ฃผ์‹  ์•„๋ž˜์˜ ๊ตฌ๊ธ€ ์นœ๊ตฌ๋“ค ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค ๐Ÿ™‡๐Ÿป‍โ™€๏ธ

https://meanbymin.tistory.com/77

https://velog.io/@theagri/macOS-BigSur%EC%97%90-MongoDB-%EC%84%A4%EC%B9%98%ED%95%98%EA%B8%B0

https://kure0406.tistory.com/49