Mongodb无法连接到本地服务器

时间:2018-05-07 15:58:15

标签: mongodb mongodb-query

当我尝试在本地连接到Mongodb时,发生以下错误。

MongoDB shell version v3.6.4
connecting to: mongodb://127.0.0.1:27017
2018-05-07T21:34:02.181+0545 W NETWORK  [thread1] Failed to connect to 127.0.0.1:27017 after 5000ms milliseconds, giving up.
2018-05-07T21:34:02.181+0545 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

我在互联网上找到了一些解决方案,其中一些人告诉我尝试先在一个终端中运行mongod,然后在另一个终端中运行mongo。我正在使用Windows,我在命令提示符下执行了此过程。

当我首先尝试运行mongod时,会遇到以下错误 -

2018-05-07T08:53:18.307-0700 I CONTROL  [initandlisten] MongoDB starting : pid=4964 port=27017 dbpath=C:\data\db\ 64-bit host=DESKTOP-8E9NTFH
2018-05-07T08:53:18.308-0700 I CONTROL  [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
2018-05-07T08:53:18.308-0700 I CONTROL  [initandlisten] db version v3.6.4
2018-05-07T08:53:18.308-0700 I CONTROL  [initandlisten] git version: d0181a711f7e7f39e60b5aeb1dc7097bf6ae5856
2018-05-07T08:53:18.308-0700 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2o-fips  27 Mar 2018
2018-05-07T08:53:18.308-0700 I CONTROL  [initandlisten] allocator: tcmalloc
2018-05-07T08:53:18.308-0700 I CONTROL  [initandlisten] modules: none
2018-05-07T08:53:18.308-0700 I CONTROL  [initandlisten] build environment:
2018-05-07T08:53:18.308-0700 I CONTROL  [initandlisten]     distmod: 2008plus-ssl
2018-05-07T08:53:18.309-0700 I CONTROL  [initandlisten]     distarch: x86_64
2018-05-07T08:53:18.309-0700 I CONTROL  [initandlisten]     target_arch: x86_64
2018-05-07T08:53:18.309-0700 I CONTROL  [initandlisten] options: {}
2018-05-07T08:53:18.309-0700 I STORAGE  [initandlisten] exception in initAndListen: NonExistentPath: Data directory C:\data\db\ not found., terminating
2018-05-07T08:53:18.309-0700 I CONTROL  [initandlisten] now exiting
2018-05-07T08:53:18.309-0700 I CONTROL  [initandlisten] shutting down with code:100

我尝试卸载并重新安装mongodb但是它存放在这里。需要你的帮助。

1 个答案:

答案 0 :(得分:2)

Mongod无法启动,因为数据路径不存在或无法访问。

exception in initAndListen: NonExistentPath: Data directory C:\data\db\ not found

创建目录应解决问题。