Mongodb
MongoDB 啟動錯誤
我正在遵循一個課程並輸入了一個給出的命令
mongod --dbpath=data --bind_ip 127.0.0.1
過去,我使用過 mongo 並且有效,但我確信我從未輸入過這個命令。現在,當我嘗試通過終端啟動 mongo 時,出現此錯誤:
MongoDB shell version v4.4.0 connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused : connect@src/mongo/shell/mongo.js:362:17 @(connect):2:6 exception: connect failed exiting with code 1
每當我嘗試啟動 mongod 時,我都會收到此錯誤:
{"t":{"$date":"2020-08-24T10:50:51.683+02:00"},"s":"I", "c":"CONTROL", "id":23285, "ctx":"main","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"} {"t":{"$date":"2020-08-24T10:50:51.715+02:00"},"s":"W", "c":"ASIO", "id":22601, "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"} {"t":{"$date":"2020-08-24T10:50:51.716+02:00"},"s":"I", "c":"NETWORK", "id":4648602, "ctx":"main","msg":"Implicit TCP FastOpen in use."} {"t":{"$date":"2020-08-24T10:50:51.721+02:00"},"s":"I", "c":"STORAGE", "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":51965,"port":27017,"dbPath":"/data/db","architecture":"64-bit","host":"22biedermann-p"}} {"t":{"$date":"2020-08-24T10:50:51.721+02:00"},"s":"I", "c":"CONTROL", "id":23403, "ctx":"initandlisten","msg":"Build Info","attr":{"buildInfo":{"version":"4.4.0","gitVersion":"563487e100c4215e2dce98d0af2a6a5a2d67c5cf","modules":[],"allocator":"system","environment":{"distarch":"x86_64","target_arch":"x86_64"}}}} {"t":{"$date":"2020-08-24T10:50:51.722+02:00"},"s":"I", "c":"CONTROL", "id":51765, "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"Mac OS X","version":"18.7.0"}}} {"t":{"$date":"2020-08-24T10:50:51.722+02:00"},"s":"I", "c":"CONTROL", "id":21951, "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{}}} {"t":{"$date":"2020-08-24T10:50:51.731+02:00"},"s":"E", "c":"STORAGE", "id":20557, "ctx":"initandlisten","msg":"DBException in initAndListen, terminating","attr":{"error":"NonExistentPath: 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."}} {"t":{"$date":"2020-08-24T10:50:51.732+02:00"},"s":"I", "c":"NETWORK", "id":20562, "ctx":"initandlisten","msg":"Shutdown: going to close listening sockets"} {"t":{"$date":"2020-08-24T10:50:51.732+02:00"},"s":"I", "c":"-", "id":20520, "ctx":"initandlisten","msg":"Stopping further Flow Control ticket acquisitions."} {"t":{"$date":"2020-08-24T10:50:51.733+02:00"},"s":"I", "c":"CONTROL", "id":20565, "ctx":"initandlisten","msg":"Now exiting"} {"t":{"$date":"2020-08-24T10:50:51.733+02:00"},"s":"I", "c":"CONTROL", "id":23138, "ctx":"initandlisten","msg":"Shutting down","attr":{"exitCode":100}}
我一直在Google搜尋並試圖找到不同的解決方案,但我不知道如何繼續。我正在使用 Mac 作業系統。
它失敗的原因就在日誌中:
未找到數據目錄 /data/db
如果您從
mongod
沒有dbPath
參數開始,它將預設為/data/db
. 在您的系統上,如果您過去使用過 MongoDB,它一定是使用不同的dbPath
,或者您已經刪除了該路徑。我建議您要麼指定不同的路徑,要麼為 MongoDB 創建 /data/db 文件夾來儲存其數據。
這對我有用:
sudo mkdir -p /data/db sudo chmod 777 /data/db