Error: couldn't connect to server 127.0.0.1:27017

window命令行连接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 :: ����Ŀ�����������ܾ����޷����ӡ� :
connect@src/mongo/shell/mongo.js:344:17
@(connect):2:6
exception: connect failed
 

解决方法:

第一步:启动MongoDB:27017端口服务,指定数据库文件夹:

最新安装的MongoDB都是默认安装了data文件夹用来存储数据库,所以,启动服务的时候无需重新创建data/db

C:\Program Files\MongoDB\Server\4.0\bin>mongod --dbpath "C:\Program Files\MongoDB\Server\4.0\data"

显示:I NETWORK  [initandlisten] waiting for connections on port 27017,即可成功访问27017端口

第二步:浏览器Test:localhost:27017

成功访问显示:It looks like you are trying to access MongoDB over HTTP on the native driver port.

 

最后:C:\Users\admin>mongo:mongo  即可成功连接

方法二:

手动打开,开启服务

你可能感兴趣的:(Error: couldn't connect to server 127.0.0.1:27017)