我選擇使用homebrew安裝
brew install mongodb
等待...
安裝完畢!

查看版本號(hào)
使用mongo -version
運(yùn)維語(yǔ)句:
To have launchd start mongodb now and restart at login:
brew services start mongodb
Or, if you don't want/need a background service you can just run:
mongod --config /usr/local/etc/mongod.conf
修改配置文件,mongodb配置文件在 /usr/local/etc/mongod.conf
【問(wèn)題記錄】
1.exception in initAndListen: NonExistentPath: Data directory /data/db not found., terminating
答:使用不加參數(shù)的mongod啟動(dòng),使用的是默認(rèn)配置,默認(rèn)使用的dbPath是 /data/db 。我并沒(méi)有創(chuàng)建這個(gè)文件件,所以會(huì)報(bào)錯(cuò)。
2.使用mongodb --config /usr/local/etc/mongod.conf 出現(xiàn)了這個(gè)
[main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
終端一直卡在這個(gè)輸出信息這里,沒(méi)有動(dòng)靜了。
3.啟動(dòng)輸出了警告:
ARNING: Access control is not enabled for the database. 2018-08-31T22:44:23.070+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted..
答:出現(xiàn)這個(gè)警告的原因是新版本的MongDB為了讓我們創(chuàng)建一個(gè)安全的數(shù)據(jù)庫(kù) 必須要進(jìn)行驗(yàn)證
新版本的MongDB增加了安全性設(shè)計(jì),推薦用戶(hù)創(chuàng)建使用數(shù)據(jù)庫(kù)時(shí)進(jìn)行驗(yàn)證。如果用戶(hù)想建立簡(jiǎn)單連接,則會(huì)提示警示信息。
使用mongo連接服務(wù)器。


重新啟動(dòng)服務(wù)器
mongod --auth
“–auth”命令即表示訪(fǎng)問(wèn)數(shù)據(jù)庫(kù)需要認(rèn)證。此處可不指定端口,則默認(rèn)為27017。
啟動(dòng)后即可看到不再提示報(bào)警信息。
4.WARNING: This server is bound to localhost.