Windows 7 机器上的 MongoDB:无法建立连接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23726684/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MongoDB on a Windows 7 machine: No connection could be made
提问by ucaiado
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:
在 Windows 7 机器上使用 mongod.exe 启动 Mongo 后,我尝试启动因错误而失败的 mongo shell:
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,原因:errno:10061 由于目标机器主动拒绝,无法建立连接。
...
...
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
错误:无法连接到服务器 127.0.0.1:27017 (127.0.0.1),在 src/mongo/shell/mongo.js:146 处连接尝试失败异常:连接失败
In the CMD where I running the mongod the output is:
在我运行 mongod 的 CMD 中,输出是:
C:\Users\Vera>mongod --dbpath c:\mongodb\mongodata
2014-05-18T17:10:10.135-0300 [initandlisten] MongoDB starting : pid=3296 port=27017 dbpath=c:\mongodb\mongodata 64-bit host=Vera-PC
2014-05-18T17:10:10.136-0300 [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
2014-05-18T17:10:10.136-0300 [initandlisten] db version v2.6.1
2014-05-18T17:10:10.136-0300 [initandlisten] git version: 4b95b086d2374bdcfcdf2249272fb552c9c726e8
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
2014-05-18T17:10:10.136-0300 [initandlisten] allocator: system
2014-05-18T17:10:10.136-0300 [initandlisten] options: { storage: { dbPath: "c:\mongodb\mongodata" } }
2014-05-18T17:10:10.242-0300 [initandlisten] journal dir=c:\mongodb\mongodata\journal
2014-05-18T17:10:10.243-0300 [initandlisten] recover : no journal files present, no recovery needed
2014-05-18T17:10:11.077-0300 [initandlisten] waiting for connections on port 27017
C:\Users\Vera>mongod --dbpath c:\mongodb\mongodata
2014-05-18T17:10:10.135-0300 [initandlisten] MongoDB 启动:pid=3296 port=27017 dbpath=c:\mongodb\mongodata 64 位主机=Vera-PC
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] git 版本:4b95b086d2374bdcfcdf2249272fb552c9c726e8
2014-05-18T17:10:10.136-0300 [initandlisten] 构建信息:windows sys.getwindowsversion(major=6,minor=1,build=7601,platform=2,service_pack='Service Pack 1')
BOOST_LIB_VERSION=1_49
2014-05-18T17:10:10.136-0300 [initandlisten] 分配器:系统
2014-05-18T17:10:10.136-0300 [initandlisten] 选项:{ storage: { dbPath: "c:\mongodb\mongodata" } }
2014-05-18T17:10:10.242-0300 [initandlisten] 日志目录=c:\mongodb\mongodata\journal
2014-05-18T17:10:10.243-0300 [initandlisten] 恢复:不存在日志文件,不需要恢复
2014-05-18T17:10:11.077-0300 [initandlisten] 等待端口 27017 上的连接
Any suggestion how to fix this issue?
任何建议如何解决这个问题?
采纳答案by ucaiado
What solved my issue was creating a file startmongo.confthat sets the bind_ipto 127.0.0.1 . After that, I just created a *.batto start the mongo using something like:
解决我的问题是创建一个文件startmongo.conf将bind_ip设置为 127.0.0.1 。之后,我刚刚创建了一个*.bat来使用以下内容启动 mongo:
mongod --config c:\mongodb\bin\startmongo.conf
mongod --config c:\mongodb\bin\startmongo.conf
More details could be seem at this post .
更多细节可以在这篇文章中看到。
回答by user1501382
I got the same error and fixed it with:
我得到了同样的错误并修复了它:
1) mkdir c:\data
1) mkdir c:\data
2) cd data
2) cd data
3) mongod -dbpath .
3) mongod -dbpath .
4) Now in another command window I was able to connect from my client using the mongo
command.
4) 现在在另一个命令窗口中,我可以使用该mongo
命令从我的客户端进行连接。
回答by Envil
I got this problem. What fixed mine is:
我遇到了这个问题。固定我的是:
- Suppose you have a dir:
"C:\mongo_databse"
Open Command Prompt and type (suppose you haved added the Mongo bin directory to PATH):
mongod --dbpath=C:/mongo_database
. There will be some log to the command prompt.Now open ANOTHERcommand prompt then type in
mongo
then it works.
- 假设你有一个目录:
"C:\mongo_databse"
打开命令提示符,类型(假设你haved添加蒙戈bin目录到PATH)
mongod --dbpath=C:/mongo_database
。命令提示符会有一些日志。现在打开另一个命令提示符然后输入
mongo
然后它就可以工作了。
回答by Basanta Dhakal
I assume your mongo.config file to be located inside the mongodb folder in the same level to the bin directory.The contents of the mongo.config file are:
dbpath=C:\mongodb\data logpath=C:\mongodb\log\mongo.log diaglog=3
don't forget to create the data folder and log folder in the same level of bin directory inside log folder create the mongo.log empty file.
Point your command prompt to C:\mongodb\binwherever your mongo db bin folder is located.
create the mongo db service in windows typing
mongod.exe --storageEngine=mmapv1 --config=../mongo.config
from now unwards you can start the mongo db service as
net start mongodb
finally you can connect to the mongo db server from the mongo db client typing
mongo.exe
once you have gone successfully from step 1 to step 3 from the next time on wards you only need the step 4 and 5.to start the service and to connect.
我假设您的 mongo.config 文件位于与 bin 目录相同级别的 mongodb 文件夹中。 mongo.config 文件的内容是:
dbpath=C:\mongodb\data logpath=C:\mongodb\log\mongo.log diaglog=3
不要忘记在日志文件夹内的同级别bin目录中创建数据文件夹和日志文件夹创建mongo.log空文件。
将命令提示符指向C:\mongodb\binmongo db bin 文件夹所在的位置。
在 Windows 输入中创建 mongo db 服务
mongod.exe --storageEngine=mmapv1 --config=../mongo.config
从现在开始,您可以启动 mongo db 服务
net start mongodb
最后,您可以从 mongo db 客户端键入连接到 mongo db 服务器
mongo.exe
一旦您从下一次病房成功地从第 1 步转到第 3 步,您只需要第 4 步和第 5 步即可启动服务并进行连接。
回答by API
I was getting a similar error when I was trying to start my mongo db via cmd. However the difference was I had a config file which has the path to the db and log folders and wanted to use the same. I was using mongo few days back and it was running fine but when I started using it again today it was giving me the error :
当我尝试通过 cmd 启动我的 mongo db 时,我遇到了类似的错误。但是,不同之处在于我有一个配置文件,其中包含 db 和 log 文件夹的路径,并且想要使用相同的文件。几天前我正在使用 mongo 并且它运行良好但是当我今天再次开始使用它时它给了我错误:
2015-05-27T10:33:22.820-0400 I CONTROL Hotfix KB2731284 or later update is installed, no need to zero-out data files
MongoDB shell version: 3.0.2
connecting to: test
2015-05-27T10:33:23.854-0400 W NETWORK Failed to connect to 27.0.0.1:27017, reason: errno:10061 No connection could be made because the target machine actively refused it.
2015-05-27T10:33:23.857-0400 E QUERY Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at connect src/mongo/shell/mongo.js:179:14) at (connect):1:6 at src/mongo/shell/mongo.js:179 exception: connect failed
Here's how I fixed it :
这是我修复它的方法:
- Open cmd as admin and navigate to the bin folder of your MongoDB and type :
mongod --config <path to your config file> --install
- Now start your mongo db service :
net start mongodb
you should get a message which says :The MongoDB service was started successfully.
- close this command prompt and open another one as admin, navigate to the bin folder once again and type
mongo
- 以管理员身份打开 cmd 并导航到 MongoDB 的 bin 文件夹并键入:
mongod --config <path to your config file> --install
- 现在启动您的 mongo db 服务:
net start mongodb
您应该收到一条消息:The MongoDB service was started successfully.
- 关闭此命令提示符并以管理员身份打开另一个命令提示符,再次导航到 bin 文件夹并键入
mongo
This will connect you to the mongodb test
.
这会将您连接到 mongodb test
。
Press ctrl+c anytime to exit.
随时按 ctrl+c 退出。
Hope this helps.
希望这可以帮助。
回答by itamar
I got this error beacuse of not sufficient space in the disk. Check your mongo log.
由于磁盘空间不足,我收到此错误。检查您的 mongo 日志。
回答by Vignesh Rathnam
1)So, i created a path
1)所以,我创建了一条路径
C:\data\db
C:\data\db
2)Now run
2)现在运行
mongod
in your terminal
mongod
在你的终端
it solved me issue!
它解决了我的问题!
回答by Daisy
I found my answer on this page. https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-mongo-app?view=aspnetcore-3.1&tabs=visual-studioSo, first, make a folder for your data; then, open one command shell
我在这个页面上找到了我的答案。https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-mongo-app?view=aspnetcore-3.1&tabs=visual-studio因此,首先,为您的数据创建一个文件夹;然后,打开一个命令外壳
mongod --dbpath <data_directory_path>
then, open another shell, do whatever you want to do. You can see in MongoDB Compass, there are collections if you had one before.
然后,打开另一个shell,做任何你想做的事。你可以在 MongoDB Compass 中看到,如果你以前有一个集合的话。
回答by maudulus
I had a very similar experience to @user1501382, but tweaked everything slightly in accordance with the documentation
我与@user1501382 的经历非常相似,但根据文档对所有内容进行了微调
1) cd c:
//changes to C drive
1) cd c:
//更改为C盘
2) mkdir data
//creates directory data
2) mkdir data
//创建目录数据
3) cd data
3) cd data
4) mkdir db
//creates directory db
4) mkdir db
//创建目录db
5) cd db
//changes directory so that you are in c:/data/db
5) cd db
//改变目录,这样你就在c:/data/db
6) run mongod -dbpath
6)运行 mongod -dbpath
7) close this terminal, open a new one and run mongod
7)关闭这个终端,打开一个新的并运行 mongod
回答by Rizwan Patel
for mongodb 3.0 versions use "--smallfiles".
对于 mongodb 3.0 版本,请使用“--smallfiles”。
e.g:-
例如:-
mongod --dbpath="C:\Program Files\MongoDB\Server\3.0" --logpath="C:\Program Files\MongoDB\Server\3.0\data\log.txt" --smallfiles --install
mongod --dbpath="C:\Program Files\MongoDB\Server\3.0" --logpath="C:\Program Files\MongoDB\Server\3.0\data\log.txt" --smallfiles --install