初次使用MongoDB征绸,安裝過程中遇到的問題:
1葫男、 現(xiàn)在MongoDB不再開源不能再通過brew安裝了翅萤,下載地址:https://www.mongodb.com/try/download/community窒盐。 下載好后解壓啃奴,把解壓后的文件放在/usr/local中潭陪。
或者用命令行下載:
# 進(jìn)入 ? ? ? ?/usr/localcd /usr/local
# 下載 ? ? ? ?sudo curl -O https://fastdl.mongodb.org/osx/mongodb-osx-ssl-x86_64-4.0.9.tgz
# 解壓????????sudo tar -zxvf mongodb-osx-ssl-x86_64-4.0.9.tgz
# 重命名為 mongodb 目錄sudo mv mongodb-osx-x86_64-4.0.9/ mongodb
2、“Data directory /data/db not found. Create the missing directory or specify another path using (1) the --dbpath command line option, or (2) by adding the 'storage.dbPath' option in the configuration file” 沒有創(chuàng)建/data/db文件
3最蕾、“mkdir: /data: Read-only file system” 創(chuàng)建/data/db文件時(shí)報(bào)這個(gè)錯(cuò)依溯,現(xiàn)在Mac不允許在根目錄下創(chuàng)建文件,隨便找個(gè)有權(quán)限的地方創(chuàng)建/data/db文件然后用?sudo mongod --dbpath="xx/data/db" 連接皆可以瘟则。
4黎炉、啟動(dòng)成功后用 'show dbs' 命令列出所有的數(shù)據(jù)庫(kù),'db' 命令列出當(dāng)前連接的數(shù)據(jù)庫(kù)醋拧,'use xx'切換數(shù)據(jù)庫(kù)慷嗜。(注意:初次使用的話可能會(huì)有疑惑,use xx不會(huì)檢測(cè)數(shù)據(jù)庫(kù)是否存在丹壕,不存在就創(chuàng)建一個(gè)庆械,但是并不是創(chuàng)建了‘show dbs’命令就會(huì)顯示,新的數(shù)據(jù)庫(kù)寫入數(shù)據(jù)后才會(huì)顯示 例如?db.test.insert({"key":"value"})后就能看到了)