Mongo - failed to connect to server 127.0.0.1:27017

I come from riak and redis, where I have never had a problem launching these services or for interaction.

This is a common problem with mongo and rather ignorant. Restarting does not help. I am new to mongo.

mongo MongoDB shell version: 2.2.1 connecting to: test Fri Nov 9 16:44:06 Error: couldn't connect to server 127.0.0.1:27017 src/mongo/shell/mongo.js:91 exception: connect failed 

This is what I see in magazines.

  now open) Fri Nov 9 16:44:34 [conn47] end connection 10.29.16.208:5306 (1 connection now open) Fri Nov 9 16:45:04 [initandlisten] connection accepted from 10.29.16.208:5307 #48 (2 connections now open) Fri Nov 9 16:45:04 [conn48] end connection 10.29.16.208:5307 (1 connection now open) Fri Nov 9 16:45:04 [initandlisten] connection accepted from 10.29.16.208:5308 #49 (2 connections now open) Fri Nov 9 16:45:04 [conn49] end connection 10.29.16.208:5308 (1 connection now open) Fri Nov 9 16:45:34 [initandlisten] connection accepted from 10.29.16.208:5316 #50 (2 connections now open) Fri Nov 9 16:45:34 [conn50] end connection 10.29.16.208:5316 (1 connection now open) Fri Nov 9 16:45:34 [initandlisten] connection accepted from 10.29.16.208:5317 #51 (2 connections now open) Fri Nov 9 16:45:34 [conn51] end connection 10.29.16.208:5317 (1 connection now open) Fri Nov 9 16:46:04 [initandlisten] connection accepted from 10.29.16.208:5320 #52 (2 connections now open) Fri Nov 9 16:46:04 [conn52] end connection 10.29.16.208:5320 (1 connection now open) Fri Nov 9 16:46:04 [initandlisten] connection accepted from 10.29.16.208:5321 #53 (2 connections now open) Fri Nov 9 16:46:04 [conn53] end connection 10.29.16.208:5321 (1 conn 
+128
mongodb pymongo
Nov 09 '12 at 16:48
source share
33 answers
  • one
  • 2

This error is what you will see if the mongo shell cannot talk to the mongod server.

This may be due to the fact that the address was incorrect (host or IP) or that it was not started. It should be noted that the provided log trace does not cover the "Fri Nov 9 16:44:06" of your mongo timestamp .

You can:

  1. Provide the command line arguments (if any) used to start the mongod process
  2. Provide log file activity since mongod started, as well as logs while trying to start mongo shell?
  3. Confirm that your mongod process is running on the same machine as the mongo shell?
+42
Nov 09 '12 at 22:24
source share

This is usually due to the fact that you did not start the mongod process before trying to start the mongo shell.

Start mongod server

 mongod 

Open another terminal window

Launch the mongo shell

 mongo 
+247
Jun 12 '13 at 17:40
source share

It is resolved.

This problem can be solved using the following 4 steps.

1) Delete the .lock file

 sudo rm /var/lib/mongodb/mongod.lock 

2) Mongodba repair

 mongod –repair 

3) start the mongod server

 sudo service mongod start 

4) run the mongo client

 mongo 

For more information, see http://shakthydoss.com/error-couldnt-connect-to-server-127-0-0-127017-srcmongoshellmongo-js-exception-connect-failed/

http://shakthydoss.com/technical/error-couldnt-connect-to-server-127-0-0-127017-srcmongoshellmongo-js-exception-connect-failed/

+70
Mar 09 '13 at 11:22
source share

This method only works if you want to restore data files without saving the original files.

To find where dbpath is located - vim / etc / mongodb.conf

check option dbpath =

(I have dbpath = / var / lib / mongodb)

Default: / data / db /

Typical locations include: / srv / mongodb, / var / lib / mongodb, or / opt / mongodb.

Replace / var / lib / mongodb with dbpath

 sudo rm /var/lib/mongodb/mongod.lock sudo mongod --dbpath /var/lib/mongodb/ --repair sudo mongod --dbpath /var/lib/mongodb/ --journal 

(Make sure you leave the terminal where you are working on lines, do not press 'Ctrl + c' or exit it.) Enter the command to start mongo now in another window.

Hope this works for you! for those who want to restore data files while saving the original mongo recover files

+35
May 04 '13 at 7:39
source share

MAC OS

Check condition

 brew services list 

Something like:

 Name Status User Plist mongodb stopped 

Start it

 brew services start mongodb 

Try again

mongo or mongo --port 27017

+15
Mar 01 '19 at 5:26
source share

Make sure your mongo is working. I fixed this problem by trying to restore mongodb, there I found that the directory needed to start db was not created. He shows this error

Type: mongod , it will show an error

exception in initAndListen: 29 Data directory /data/db not found., terminating

The error occurs because dbpath /data/db/ (default setting) does not exist. You need to create a data folder and set permission for it.

Then I create a folder in my system with the command

sudo mkdir -p / data / db / as well as sudo chown id -u / data / db

Then I run the mongo again and it worked.

+12
May 08 '16 at 3:28
source share

In my case:

First I open the configuration file

 sudo vi /etc/mongodb.conf 

Comment IP and port as

 #bind_ip = 127.0.0.1 #port = 27017 

Then restart mongodb

 sudo service mongodb restart sudo service mongod restart 

Finally it works: D

 finn@Finn ~ $ mongo MongoDB shell version: 2.4.9 connecting to: test > exit 
+11
Jan 12 '16 at 16:10
source share

A bit late with the answer, but I ran into the same problem

Below are the steps that helped me.

  • Go to C: \
  • Create Data Folder
  • In the "data" create a folder "db"
  • open terminal (CMD) -> go to EX: " c:\MongoDB\Server\3.4\bin "
  • type mongod => this will start the mongo server (leave it open)

Starting using the GUI, EX "robomongo"

Or

open a new terminal (CMD) β†’ go to EX: " c:\MongoDB\Server\3.4\bin " enter the command "mongo"

+9
Nov 08 '17 at 11:34 on
source share

If all of the above solution does not work: go to the service ( start>search>services ) and start the mongodb service. Then at the cmd prompt after going to bin, type :/>mongo

+4
Jul 20 '14 at 7:46
source share

I am a Windows user and I installed MongoDB in November 2018, and I did not want to configure / db data directories. But a few days later, when I opened, an error message appeared:

 MongoDB shell version v4.0.4 connecting to: mongodb://127.0.0.1:27017 2018-12-05T20:42:40.108+0530 E QUERY [js] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: No connection could be made because the target machine actively refused it. : connect@src/mongo/shell/mongo.js:257:13 @(connect):1:6 exception: connect failed 

Then I tried to fix all of the above answers and did not work. When I tried to start mongod, he said:

 MongoDB starting : pid=12220 port=27017 dbpath=C:\data\db\ 64-bit host=bla 

I tried changing the db path (to the program files) through the file system and also using cmd, but they did not work.

Solution that worked for me:

Opened the tab " Task Manager" ( ctrl + shift + esc ) β†’ Services and a line appeared MongoDB with stopped status . Then I right-clicked and hit the start button, and everything works fine :) .

+4
Dec 05 '18 at 15:22
source share

To connect to the mongo, we must first start the mongod services. You can see the following result:

 $ mongod 2017-03-05T00:31:39.055+0530 I CONTROL [initandlisten] MongoDB starting : pid=1481 port=27017 dbpath=/data/db 64-bit host=Prabhu-Nandans-Mac.local 2017-03-05T00:31:39.056+0530 I CONTROL [initandlisten] db version v3.4.2 2017-03-05T00:31:39.056+0530 I CONTROL [initandlisten] git version: 3f76e40c105fc223b3e5aac3e20dcd026b83b38b 2017-03-05T00:31:39.056+0530 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2k 26 Jan 2017 2017-03-05T00:31:39.056+0530 I CONTROL [initandlisten] allocator: system 2017-03-05T00:31:39.056+0530 I CONTROL [initandlisten] modules: none 2017-03-05T00:31:39.056+0530 I CONTROL [initandlisten] build environment: 2017-03-05T00:31:39.056+0530 I CONTROL [initandlisten] distarch: x86_64 2017-03-05T00:31:39.056+0530 I CONTROL [initandlisten] target_arch: x86_64 2017-03-05T00:31:39.056+0530 I CONTROL [initandlisten] options: {} 2017-03-05T00:31:39.056+0530 W - [initandlisten] Detected unclean shutdown - /data/db/mongod.lock is not empty. 2017-03-05T00:31:39.057+0530 I - [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'. 2017-03-05T00:31:39.057+0530 W STORAGE [initandlisten] Recovering data from the last clean checkpoint. 2017-03-05T00:31:39.057+0530 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=3584M,session_max=20000,eviction=(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-03-05T00:31:39.620+0530 I CONTROL [initandlisten] 2017-03-05T00:31:39.620+0530 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database. 2017-03-05T00:31:39.620+0530 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted. 2017-03-05T00:31:39.620+0530 I CONTROL [initandlisten] 2017-03-05T00:31:39.620+0530 I CONTROL [initandlisten] 2017-03-05T00:31:39.620+0530 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000 2017-03-05T00:31:39.643+0530 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data' 2017-03-05T00:31:39.643+0530 I NETWORK [thread1] waiting for connections on port 27017 2017-03-05T00:31:40.008+0530 I FTDC [ftdc] Unclean full-time diagnostic data capture shutdown detected, found interim file, some metrics may have been lost. OK 2017-03-05T00:32:03.832+0530 I NETWORK [thread1] connection accepted from 127.0.0.1:49806 #1 (1 connection now open) 2017-03-05T00:32:03.833+0530 I NETWORK [conn1] received client metadata from 127.0.0.1:49806 conn1: { application: { name: "MongoDB Shell" }, driver: { name: "MongoDB Internal Client", version: "3.4.2" }, os: { type: "Darwin", name: "Mac OS X", architecture: "x86_64", version: "16.4.0" } } 2017-03-05T00:32:08.376+0530 I - [conn1] end connection 127.0.0.1:49806 (1 connection now open) 

After that, open another terminal and just enter "mongo".

After the output, you can see:

 $ mongo MongoDB shell version v3.4.2 connecting to: mongodb://127.0.0.1:27017 MongoDB server version: 3.4.2 

Your problem has been resolved :)

+3
Mar 04 '17 at 19:20
source share

I also have the same problem, after which I fixed these two lines of code. Hope help

 systemctl start mongod systemctl enable mongod 
+2
Jul 03 '18 at 2:52
source share

Another solution that resolved this error for me, although it can only be if you are accessing mongo (locally) through an SSH connection through a virtual machine (at least my setup) and may be a specific Linux environment with variable:

 export LC_ALL=C 

Also, I had a better chance of starting mongo as a daemon service and then running sudo, I understand that this uses command line arguments and not a configuration file, so this is probably the problem with my configuration file:

 mongod --fork --logpath /var/log/mongodb.log --auth --port 27017 --dbpath /var/lib/mongodb/admin 
+1
Feb 18 '16 at 11:52
source share

Create a C: data / db folder if it does not already exist on your computer. Turns out MongoDB requires this folder structure 'data / db' to run. Hope this helps someone.

+1
Feb 28 '17 at 13:42 on
source share

The reason for me was space - run this in the console:

 df -h 

or more specifically:

 du -hs /var/lib/mongodb/ 

to check its use on disk. If it is ~ 99% - just clear some space and try again!

+1
Nov 07 '17 at 16:05
source share

First go to c:\mongodb\bin> to enable mongoDB, if you see on the console that mongo is listening on port 27017, that’s fine. If not, close the console and create the folder c:\data\db and run mongod again

+1
Dec 20 '17 at 6:19 06:19
source share

You can try the following command:

sudo service mongod start

+1
May 23 '18 at 6:23
source share

This happened to me today, and I decided it as follows.

Machine: I use a Windows 10 machine and download the latest version of MongoDB - Community.

So the problem was that I did not have C:\data\db .

Without creating C:\data\db I opened the CMD terminal and started the database using the mongod command on the terminal

C: \ YourInstallationPath \ Bin> mongod

And when I fired the mongo team me mongo problem.

Twist, I created the necessary folders, but there was still a problem. And this is because the mongo server is already running. To fix this, I again mongod command and automatically referred to C:\data\db .

Other users suggested adding C:\data\db but did not talk about running mongod again, which definitely solved my problem.

+1
May 25 '18 at 8:13
source share

if all of the above solution fails, maybe this may help. Somewhere along the line, you could connect to the local mongodb database through roaming boxes.

  1. and then ssh to your roaming machine where you connected to mongodb (vagrant ssh vagrant_box_name)
  2. comment out the bind_ip line from /etc/mongod.conf using # (sudo nano / etc / mongod.conf)
  3. restart the mongodb daemon service (sudo service mongod restart) voila ...
+1
Jun 20 '18 at 18:02
source share

@shakthydoss the answer worked fine once, but after the second problem, there was no lock, I just created an empty one and it worked fine. So check if you have one.

If you use the command line:

 cd /var/lib/mongodb ls 

"ls" lists all the files in the folder, if mongod.lock does not exist, then:

 sudo touch mongod.lock 

Finally, run the command.

 mongod –-repair sudo service mongod start 

The Mongo service should work fine.

+1
Sep 26 '18 at 14:25
source share

I had the same problem to connect mongodb after installation using brew on macOS.

The problem was also in mongod.lock but before I installed mongodb 3.6, the database directory was /usr/local/var/mongodb and it had old files and mongod.lock

I just moved my old database files to another folder and deleted everything from /usr/local/var/mongodb

Then restarted:

 brew services restart mongodb 

And now it works fine.

+1
May 08 '19 at 3:34
source share

Delete the mongod.lock file. And run the "mongod -repair". uninstall / reinstall mongod service, fixed this problem for me.

Thank.

0
Aug 6 '13 at
source share

I had the same error when connecting to Mongo on AWS EC2. This is exactly what decided https://serverfault.com/a/347159/62381 Remove bind_ip from the configuration file

0
Jul 31 '15 at 16:01
source share

This work is for me: -

In Mongo 3.2, for a window, you must start the Mongodb service. So run Command Prompt as Administrator , then net start MongoDB

0
Jan 07 '16 at 5:49
source share

Finally, I realized that it is simple.

open a terminal and go to the mongodb location. In my case it is

 e:\mongodb\bin> 

and enter the following command and press enter.

 mongod --config e:\mongodb\mongo.config 

Open another terminal and run mongodb using

 mongo.exe 

Here it is .. you can use mongo

0
May 29 '16 at 10:46
source share

This is an old question, but as a beginner, I decided that I would add that (using Webstorm) you need to click on Mongo Explorer (the tab on the right side of the window). From there:

-Click on the settings. -Click the browse button (looks like a button labeled "..."). -Go for program files> MongoDB> Server> 3.4> bin> mongo.exe (your version may differ from 3.4) -After that, click the green plus sign on the right. A window will open -Enter the name in the "Label" slot. -Click "Apply."

You should now be connected. Putting "mongod" in the terminal is not enough. You must also complete the above steps.

I apologize in advance to those who do not use Webstorm! Unsure of actions using other IDEs.

0
Mar 09 '17 at 2:23
source share

if u is installed using brew (by osx), start sudo mkdir /data/db start mondoDB Daemon by typing mongod (leave it open), and then start mongo by typing mongo in a new terminal tab

0
May 15 '17 at 7:43
source share

Just create a folder called "data" on drive C and inside the data folder create another folder called "db". Then run mongod.exe :)

0
Mar 31 '18 at 6:32
source share

First, you need to start the mongod server , and then in another terminal you have to start the mongo shell.

To start, mongo server

1. If you use the default path (data / db), the simplest mongod firing in the terminal

2. If your path is not / db, then you will run as follows: mongod --dbpath "here is your path" .

To launch the mango shell, just shot the mongo at another terminal

If you expect to connect to port 27017 , your mongo will start successfully.

I hope you can get my point

0
Apr 05 '18 at 5:07
source share

I had the same problem, I deleted the file E: \ Mongo Data Files \ db \ mongod.lock, so it started working. The problem is due to incorrect shutdown of the server. therefore, the lock file is not clean.

0
Jun 24 '18 at 11:21
source share
  • one
  • 2



All Articles