身思乐,人事爱,稳恒不言败!

mac 下mongodb connect failed 连接错误

MongoDB shell version v3.6.0
connecting to: mongodb://127.0.0.1:27017
2018-04-12T22:26:50.166+0800 W NETWORK  [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2018-04-12T22:26:50.169+0800 E QUERY    [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:251:13
@(connect):1:6
exception: connect failed

当mongodb service 没有运行的时候会发生这样的错误

尝试了新建一个/data/db 目录,但不奏效

最后找到了如下方法解决

然后 在bash 输入

brew services start mongodb

再输入mongo进入数据库

mongo

回车,成功了!

from:https://www.cnblogs.com/timtike/p/6629764.html