官網下載下傳: https://www.mongodb.com/download-center?jmp=nav#community 參考文檔: http://www.runoob.com/mongodb/mongodb-tutorial.html
macos安裝:
brew install mongodb
建立一個資料庫存儲目錄
sudo mkdir -p /data/db
啟動資料庫
sudo mongod
背景啟動
mongod --dbpath=/data/db --fork --logpath=/data/logs
# 或者指定配置檔案啟動
sudo mongod --config /usr/local/etc/mongod.conf
說明:
- dbpath是存放資料庫的路徑
- fork是背景啟動
- logpath是日志路徑 這些都不可缺少
進入資料庫
mongo
函數文法類似javascript
BSON是一種類json的一種二進制形式的存儲格式,簡稱Binary JSON
報錯
mongodb: A full installation of Xcode.app 8.3.2 is required to compile this software.
Installing just the Command Line Tools is not sufficient.
Xcode can be installed from the App Store.
Error: An unsatisfied requirement failed this build.
Xcode版本低,需要更新,或者安裝低版本的mongo
brew search mongodb # 檢視mongo的版本
brew install [email protected] # 安裝低版本
brew services start [email protected] # 啟動MongoDB服務
brew services stop [email protected] # 關閉MongoDB服務
mongo # 進入MongoDB圖形化界面
# 通路遠端mongo
mongo 127.0.0.1:27017/test -u user -p password
brew services list # 檢視homebrew安裝的服務情況
參考:
mac 下mongo的啟動和關閉以及啟動問題解決