Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Erro

一、错误提示:

Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Erro
Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Erro_第1张图片

二、解决方法:

在你安装MongoDB的目录下创建一个文件夹data,并在里面创建db文件夹:
Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Erro_第2张图片
Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Erro_第3张图片
打开两个终端(以管理员身份运行):
(1)第一个终端执行命令:

mongod --dbpath D:\MongoDB\data\db

Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Erro_第4张图片

(2)第二个终端执行命令:

mongo

在这里插入图片描述
Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Erro_第5张图片

三、问题原因

要与mongo连接,必须首先启动'mongod'服务

你可能感兴趣的:(其它,mongodb,数据库)