MongoDB安裝

系統使用Ubuntu 20.04

在新系統裝好後,先 apt update 跟 apt upgrade 更新一下後再正式開始。

安裝指令:

# apt install mongodb

檢查MongoDB啟動狀態

# systemctl status mongodb

看到active (running)就知道應該正常運作了

啟動MongoDB

# systemctl start mongodb

停止運行

# systemctl stop mongodb

開機時自動啟動

# systemctl enable mongodb

開機時取消自動啟動

# systemctl disable mongodb

使用Mongo Shell

# mongo

輸入exit 或是 quit() 可以離開

這個可能不太需要用到,還是紀錄一下怎麼移除MongoDB,簡單說就是先停用再移除

# systemctl stop mongodb

# apt purge mongodb

# apt autoremove

MongoDB的設定檔應該會是在  /etc/mongodb.conf

如果要對外開放連線,可以把這檔案內的 bind_ip = 127.0.0.1 前面加個#給註解起來。

或是指定可以連線的IP,IP之間用逗號分開,例如這樣:    bind_ip = 127.0.0.1,10.140.0.17

然後重新啟動就可以。

預設會打開的PORT是 27017