macOS 설치 공식문서 👉 https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-os-x/
Linux 설치 공식문서 👉 https://www.mongodb.com/docs/manual/administration/install-on-linux/
$ brew tab mongodb/brew
$ brew search mongodb
==> Formulae
mongodb-atlas-cli mongodb/brew/mongodb-community@4.2
mongodb/brew/libmongocrypt mongodb/brew/mongodb-community@4.4
mongodb/brew/mongocli mongodb/brew/mongodb-database-tools
mongodb/brew/mongodb-community mongodb/brew/mongodb-mongocryptd
mongodb/brew/mongodb-community-shell mongodb/brew/mongodb-mongocryptd@4.2
mongodb/brew/mongodb-community@3.2 mongodb/brew/mongodb-mongocryptd@4.4
mongodb/brew/mongodb-community@3.4 mongosh
mongodb/brew/mongodb-community@3.6 monetdb
mongodb/brew/mongodb-community@4.0
==> Casks
gcollazo-mongodb
mongodb-compass
mongodb-compass-isolated-edition
mongodb-compass-readonly
mongodb-realm-studio
mongodbpreferencepane
nosqlbooster-for-mongodb
mongotron
homebrew/cask-versions/mongodb-compass-beta
$ brew install mongodb-community@4.4
m1 맥북 모델의 경우 위의 명령어로 설치하면 오류가 발생하는데, 이는 brew 명령어 앞에 arch -arm64
를 붙여주면 잘 설치된다
$ arch -arm64 brew install mongodb-community@4.4
$ mongo -version
$ brew services start mongodb-community@4.4
서버를 실행시키고 http://localhost:27017 에 접속 시 아래와 같은 문구가 뜨면 잘 실행된 것
It looks like you are trying to access MongoDB over HTTP on the native driver port.
$ mongo
$ brew services stop mongodb-community@4.4
$ brew services list
Name Status User File
mongodb-community@4.4 started hwwwa ~/Library/LaunchAgents/homebrew.mxcl.mongodb-community@4.4.plist
$ brew info mongodb-community@4.4
mongodb/brew/mongodb-community@4.4: stable 4.4.13 [keg-only]
High-performance, schema-free, document-oriented database
https://www.mongodb.com/
/opt/homebrew/Cellar/mongodb-community@4.4/4.4.13 (11 files, 157.6MB)
Built from source on 2022-04-17 at 22:17:37
From: https://github.com/mongodb/homebrew-brew/blob/HEAD/Formula/mongodb-community@4.4.rb
==> Dependencies
Recommended: mongodb-database-tools ✔
==> Options
--without-mongodb-database-tools
Build without mongodb-database-tools support
==> Caveats
mongodb-community@4.4 is keg-only, which means it was not symlinked into /opt/homebrew,
because this is an alternate version of another formula.
If you need to have mongodb-community@4.4 first in your PATH, run:
echo 'export PATH="/opt/homebrew/opt/mongodb-community@4.4/bin:$PATH"' >> ~/.zshrc
To restart mongodb/brew/mongodb-community@4.4 after an upgrade:
brew services restart mongodb/brew/mongodb-community@4.4
Or, if you don't want/need a background service you can just run:
mongod --config /opt/homebrew/etc/mongod.conf
If you need to have mongodb-community@4.4 first in your PATH, run: echo 'export PATH="/opt/homebrew/opt/mongodb-community@4.4/bin:$PATH"' >> ~/.zshrc
라고 알려줌$ vi ~/.zshrc
vi편집기를 이용해서 아래 내용 추가
...
export PATH="/opt/homebrew/Cellar/mongodb-community@4.2/4.2.18/bin:$PATH"
...
$ mongo
MongoDB shell version v4.4.13
...
>
> exit
> use admin
switched to db admin
> db.createUser({ user: "mongo", pwd: "password123", roles: ["root"] })
Successfully added user: { "user" : "mongo", "roles" : [ "root" ] }
> mongo admin -u 아이디 -p 비번
> use db이름
> show dbs
> db
> db.createUser({ user: "youruser", pwd: "yourpassword", roles: [{ role: "dbOwner", db: "사용중인 db 이름" }] })
db
명령어로 현재 사용중인 데이터베이스 확인 필요> db.dropUser("username")
> db.getUsers()