我是用brew install mongod 安裝的
MongoDB shell version v3.4.2
connecting to: mongodb://127.0.0.1:27017
2017-03-28T02:11:34.775+0800 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2017-03-28T02:11:34.778+0800 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:237:13
@(connect):1:6
exception: connect failed
當mongodb service 沒有運行的時候會發生這樣的錯誤
嘗試了新建一個/data/db 目錄,但不奏效
最后找到了如下方法解決
然后 在bash 輸入
brew services start mongodb
再輸入mongo進入數據庫
mongo
回車,成功了!