无法连接到mongo服务器

时间:2017-11-18 04:16:42

标签: mongodb

enter image description here我正在使用mongoDb V 3.4并尝试启动服务器,但它说

C:\Users\gokul ram>mongo
MongoDB shell version v3.4.10
connecting to: mongodb://127.0.0.1:27017
2017-11-18T09:25:27.061+0530 W NETWORK  [thread1] Failed to connect to 127.0.0.1:27017 after 5000ms milliseconds, giving up.
2017-11-18T09:25:27.062+0530 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

我也尝试过使用--dbpath命令,但它正在等待很长时间的连接,仍然没有连接

C:\Program Files\MongoDB\Server\3.4\bin>mongod --dbpath "C:/data/db"
2017-11-18T09:36:03.368+0530 I CONTROL  [initandlisten] MongoDB starting :     pid=4660 port=27017 dbpath=C:/data/db 64-bit host=GOK_RAM
2017-11-18T09:36:03.370+0530 I CONTROL  [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
2017-11-18T09:36:03.370+0530 I CONTROL  [initandlisten] db version v3.4.10
2017-11-18T09:36:03.371+0530 I CONTROL  [initandlisten] git version: 078f28920cb24de0dd479b5ea6c66c644f6326e9
2017-11-18T09:36:03.371+0530 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.1u-fips  22 Sep 2016
2017-11-18T09:36:03.371+0530 I CONTROL  [initandlisten] allocator: tcmalloc
2017-11-18T09:36:03.371+0530 I CONTROL  [initandlisten] modules: none
2017-11-18T09:36:03.371+0530 I CONTROL  [initandlisten] build environment:
2017-11-18T09:36:03.371+0530 I CONTROL  [initandlisten]     distmod: 2008plus-ssl
2017-11-18T09:36:03.371+0530 I CONTROL  [initandlisten]     distarch: x86_64
2017-11-18T09:36:03.372+0530 I CONTROL  [initandlisten]     target_arch: x86_64
2017-11-18T09:36:03.372+0530 I CONTROL  [initandlisten] options: { storage: { dbPath: "C:/data/db" } }
2017-11-18T09:36:03.375+0530 I -        [initandlisten] Detected data files in C:/data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2017-11-18T09:36:03.376+0530 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=1509M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2017-11-18T09:36:04.096+0530 I CONTROL  [initandlisten]
2017-11-18T09:36:04.097+0530 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-11-18T09:36:04.097+0530 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2017-11-18T09:36:04.098+0530 I CONTROL  [initandlisten]
2017-11-18T09:36:04.098+0530 I CONTROL  [initandlisten] Hotfix KB2731284 or later update is not installed, will zero-out data files.
2017-11-18T09:36:04.098+0530 I CONTROL  [initandlisten]
2017-11-18T09:36:05.880+0530 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory 'C:/data/db/diagnostic.data'
2017-11-18T09:36:05.882+0530 I NETWORK  [thread1] waiting for connections on port 27017

mongo db版本或我的配置有问题吗?任何遇到同样的问题请帮帮我!提前致谢

3 个答案:

答案 0 :(得分:1)

首先:导航至C:\Program Files\MongoDB\Server\3.4\bin\并运行 mongod.exe ,这将启动服务器。

:在 mongo 中的新cmd类型中  这可能有用

答案 1 :(得分:1)

首先需要使用' mongod.exe'启动mongo服务器。命令和设置数据\ db'作为将存储数据的dbpath。确保在运行命令之前创建了文件夹。 将C:\ Program Files \ MongoDB \ Server \ 3.4 \ bin \添加到您的环境变量' PATH'会有益的。 要运行服务器,请在cmd提示符下键入以下命令: mongod --dbpath = C:\ data \ db 服务器应使用端口27017的默认设置运行

要连接到服务器,请打开另一个cmd提示符并执行' mongo.exe'命令。这应该工作。 否则你可以尝试指定端口号" mongo --port 27017"

答案 2 :(得分:0)

<强>第一 我们需要使用--dbpath命令启动mongo服务器

下一步打开单独的命令窗口, 设置mongo bin的路径并使用mongo.exe命令

然后你就可以开始访问mongo服务器了。