Mac下mongodb connect failed 连接错误解决方法
这几天一直在折腾mongodb数据库,一直出现如下这个问题
MongoDB shell version v3.6.0 connecting to: mongodb://127.0.0.1:27017 2017-12-27T09:54: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-12-27T09:54: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 目录,也不奏效。
后来通过搜索,寻找到来解决方法,运行命令
brew services start mongodb
再去调用数据库命令
mongo
就可以完美解决问题了
最终mac下显示成功的提示
MongoDB shell version v3.6.0 connecting to: mongodb://127.0.0.1:27017 MongoDB server version: 3.6.0 Server has startup warnings: 2017-12-27T09:54:58.316+0800 I CONTROL [initandlisten] 2017-12-27T09:54:58.316+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database. 2017-12-27T09:54:58.316+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted. 2017-12-27T09:54:58.316+0800 I CONTROL [initandlisten] >