Mongodb: Failed to connect to 127.0.0.1:27017, rea

2019-01-08 06:39发布

Here is my mongod.cfg file:

bind_ip = 127.0.0.1
dbpath = C:\mongodb\data\db
logpath = C:\mongodb\log\mongo-server.log
verbose=v

Here is my mongod service command:

mongod -f c:\mongodb\mongod.cfg --install

I have installed MongoDB about a week ago and it all worked fine, however today when I ran mongo command I got the following error:

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

How can I fix that? I use Windows 8.1

Solution:

I forgot to start mongodb service with this command:

net start mongodb

Improved solution:

1) Change directory to root drive C:\, and type the command below into an admin cmd prompt window,

C:\mongodb\bin\mongod.exe --config c:\mongodb\mongod.cfg --install

2) Then type net start MongoDB after which you should see the following message:

"The Mongo DB service was started successfully"

3) Then go to the control panel Start>Administrative Tools>Services, scroll down to MongoDB in the list of services and change start up type to automatic, if you so desire. Press OK.

4) Finally type C:\mongodb\bin\mongo.exe and you should be connected to the Mongo test DB.

Reference: https://www.youtube.com/watch?v=-mik4dPArCU

17条回答
Emotional °昔
2楼-- · 2019-01-08 07:20

This is how I solved it, You can follow step by step here:

MongoDB Steps:

  • Download the latest 64-bit MSI version of MongoDB for Windows.

  • Run the installer (.msi file)

  • Add it to your PATH of environment variables. it Should be from:
    C:\Program Files\MongoDB\Server\3.0\bin

now Create a “\data\db” folder in C:/ which is used by mongodb to store all data. You should have this folder:

C:\data\db

Note: This is the default directory location expected by mongoDB, don’t create anywhere else

.

Finally, open command prompt and type:

>> mongod

You should see it asking for permissions (allow it) and then listen to a port. After that is done, open another command prompt, leaving the previous one running the server.

Type in the new command prompt

>> mongo

You should see it display the version and connect to a test database.

This proves successful install!=)

Reference link

查看更多
Fickle 薄情
3楼-- · 2019-01-08 07:22

If it writes that you had not properly shut down or that mongod.lock is not empty , only delete mongod.lock from C:\data\db\ and it will start.

查看更多
forever°为你锁心
4楼-- · 2019-01-08 07:24

just create a folder

C:\data\db 

Run below commands in command prompt

C:\Program Files\MongoDB\Server\3.4\bin>mongod

Open another command prompt

C:\Program Files\MongoDB\Server\3.4\bin>mongo
查看更多
一夜七次
5楼-- · 2019-01-08 07:25

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:\mongodb\bin\startmongo.conf
查看更多
啃猪蹄的小仙女
6楼-- · 2019-01-08 07:26

The problem is that I missed out 'db' folder for the dbpath in the command:

C:\mongodb\bin> mongod --directoryperdb --dbpath C:\mongodb\data\db --logpath C:\mongodb\log\mongodb.log --logappend -rest --install
查看更多
登录 后发表回答