Windows 7 机器上的 MongoDB:无法建立连接

问题描述:

在 Windows 7 机器上使用 mongod.exe 启动 Mongo 后,我尝试启动因错误而失败的 mongo shell:

After I have started Mongo using mongod.exe on a Windows 7 machine, I tried to start the mongo shell that failed with the error:

无法连接到 127.0.0.1:27017,原因:errno:10061 否由于目标机器主动拒绝,可以建立连接

Failed to connect to 127.0.0.1:27017, reason: errno:10061 No connection could be made because the target machine actively refused it.

...

错误:无法连接到服务器 127.0.0.1:27017 (127.0.0.1),连接尝试在 src/mongo/shell/mongo.js:146 异常处失败:连接失败

Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146 exception: connect failed

在我运行 mongod 的 CMD 中,输出是:

In the CMD where I running the mongod the output is:

C:UsersVera>mongod --dbpath c:mongodbmongodata

C:UsersVera>mongod --dbpath c:mongodbmongodata

2014-05-18T17:10:10.135-0300 [initandlisten] MongoDB 开始:pid=3296 port=27017 dbpath=c:mongodbmongodata 64位主机=Vera-PC

2014-05-18T17:10:10.135-0300 [initandlisten] MongoDB starting : pid=3296 port=27017 dbpath=c:mongodbmongodata 64-bit host=Vera-PC

2014-05-18T17:10:10.136-0300 [initandlisten] targetMinOS: Windows7/Windows Server 2008 R2

2014-05-18T17:10:10.136-0300 [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2

2014-05-18T17:10:10.136-0300 [initandlisten] db 版本 v2.6.1

2014-05-18T17:10:10.136-0300 [initandlisten] db version v2.6.1

2014-05-18T17:10:10.136-0300 [initandlisten] git 版本:4b95b086d2374bdcfcdf2249272fb552c9c726e8

2014-05-18T17:10:10.136-0300 [initandlisten] git version: 4b95b086d2374bdcfcdf2249272fb552c9c726e8

2014-05-18T17:10:10.136-0300 [initandlisten] 构建信息:windowssys.getwindowsversion(主要=6,次要=1,构建=7601,平台=2,service_pack='Service Pack 1')

2014-05-18T17:10:10.136-0300 [initandlisten] build info: windows sys.getwindowsversion(major=6, minor=1, build=7601, platform=2, service_pack='Service Pack 1')

BOOST_LIB_VERSION=1_49

BOOST_LIB_VERSION=1_49

2014-05-18T17:10:10.136-0300 [initandlisten] 分配器:系统

2014-05-18T17:10:10.136-0300 [initandlisten] allocator: system

2014-05-18T17:10:10.136-0300 [initandlisten] 选项:{ 存储:{dbPath: "c:mongodbmongodata" } }

2014-05-18T17:10:10.136-0300 [initandlisten] options: { storage: { dbPath: "c:mongodbmongodata" } }

2014-05-18T17:10:10.242-0300 [initandlisten] 期刊dir=c:mongodbmongodatajournal

2014-05-18T17:10:10.242-0300 [initandlisten] journal dir=c:mongodbmongodatajournal

2014-05-18T17:10:10.243-0300 [initandlisten] 恢复:没有日志文件存在,无需恢复

2014-05-18T17:10:10.243-0300 [initandlisten] recover : no journal files present, no recovery needed

2014-05-18T17:10:11.077-0300 [initandlisten] 等待连接在端口 27017 上

2014-05-18T17:10:11.077-0300 [initandlisten] waiting for connections on port 27017

有什么建议可以解决这个问题吗?

Any suggestion how to fix this issue?

解决我的问题是创建一个文件 startmongo.confbind_ip 设置为 127.0.0.1.在那之后,我刚刚创建了一个 *.bat 来使用以下内容启动 mongo:

What solved my issue was creating a file startmongo.conf that sets the bind_ip to 127.0.0.1 . After that, I just created a *.bat to start the mongo using something like:

mongod --config c:mongodbinstartmongo.conf

可以在此帖子中查看更多详细信息.

More details could be seem at this post .