Failed to connect to 127.0.0.1:27017, reason: errno: 111 Connection refused

when trying to execute mongo command in ubuntu I get this error.

ritzysystem@ritzysystem-Satellite-L55-A:~$ mongo MongoDB shell version: 2.6.1 connecting to: test 2014-10-06T12:59:35.802+0530 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused 2014-10-06T12:59:35.802+0530 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 

How can I fix this, someone had the same problem.

+67
mongodb express
Oct 06 '14 at 7:32
source share
24 answers

Thanks to everyone, I tried to run mongo, it did not work, finally, I found that there was no free space on my hard disk. I emptied part of the space and finally installed the same installation procedure as for the installation, as indicated in the docs mongodb finally restarted the server and it started.

https://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu

+20
Oct 06 '14 at 11:32
source share

Run the following command:

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

Connection refused MongoDB errno 111

MacOS:

 rm /usr/local/var/mongodb/mongod.lock sudo service mongod restart 
+91
Dec 04 '14 at 9:47
source share

I had the same problem on Mac OS Try running sudo mongod and in the new terminal tab run mongo

+27
Oct 18 '14 at 14:34
source share

In my case, the error was caused by the missing / data / db folder that mongodb uses to store your data. Enter the command $sudo mongod in your terminal. If the error message looks something like this:

missing data/db folder error

Just create a folder and you will go well.

+15
Sep 14 '16 at 10:18
source share

First, Start MongoDB:

 sudo service mongod start 

Then Run:

 mongo 
+9
Sep 03 '17 at 1:03 on
source share

You may not have space on your hard drive. Check this by typing df -h in miss

Please note that mongo may fail even with 3gb in the corresponding section. For more information, you can check the log: cat /var/log/mongodb/mongod.log

+7
Oct 13 '14 at 20:02
source share

I had the same problem on my Mac and I installed mongodb using homebrew. I solve this problem with the homebrew services team.

The first launch of mongodb service:

$ brew services start mongodb

Launch mongodb terminal

$ mongo

Stop the mongodb service:

$ brew services stop mongodb

+7
Jan 10 '18 at 11:22
source share

Before connecting the console, make sure that you start the MongoDB service.

start and start the server:

 $ sudo mongod 

then

 $ mongo ... > 
+5
Aug 23 '15 at 13:05
source share

Do it:

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

If you are on Ubuntu 16.04, which you can determine with runnign this:

 lsb_release -a 

You need to create a new file in /lib/systemd/system/mongod.service with the following contents:

 [Unit] Description=High-performance, schema-free document-oriented database After=network.target Documentation=https://docs.mongodb.org/manual [Service] User=mongodb Group=mongodb ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf [Install] WantedBy=multi-user.target 
+5
Aug 30 '16 at 6:43
source share

I think that besides issuse disk space, you should check the /var/log/mongodb for details on why mongodb start failed.

 cat /var/log/mongodb/mongod.log 2016-06-26T15:26:26.642+0800 I CONTROL [main] ***** SERVER RESTARTED ***** 2016-06-26T15:26:26.649+0800 I CONTROL [initandlisten] MongoDB starting : pid=8130 port=27017 dbpath=/var/lib/mongodb 64-bit host=hadoop-master 2016-06-26T15:26:26.649+0800 I CONTROL [initandlisten] db version v3.2.7 2016-06-26T15:26:26.649+0800 I CONTROL [initandlisten] git version: 4249c1d2b5999ebbf1fdf3bc0e0e3b3ff5c0aaf2 2016-06-26T15:26:26.649+0800 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1f 6 Jan 2014 2016-06-26T15:26:26.649+0800 I CONTROL [initandlisten] allocator: tcmalloc 2016-06-26T15:26:26.649+0800 I CONTROL [initandlisten] modules: none 2016-06-26T15:26:26.649+0800 I CONTROL [initandlisten] build environment: 2016-06-26T15:26:26.649+0800 I CONTROL [initandlisten] distmod: ubuntu1404 2016-06-26T15:26:26.649+0800 I CONTROL [initandlisten] distarch: x86_64 2016-06-26T15:26:26.649+0800 I CONTROL [initandlisten] target_arch: x86_64 2016-06-26T15:26:26.649+0800 I CONTROL [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1,192.168.3.10", port: 27017 }, storage: { dbPath: "/var/lib/mongodb", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } } 2016-06-26T15:26:26.678+0800 E NETWORK [initandlisten] Failed to unlink socket file /tmp/mongodb-27017.sock errno:1 Operation not permitted 2016-06-26T15:26:26.678+0800 I - [initandlisten] Fatal Assertion 28578 2016-06-26T15:26:26.678+0800 I - [initandlisten] ***aborting after fassert() failure 

So here I need rm all the files in /tmp . This works great for me.

+4
Jun 26 '16 at 7:30
source share

In my case, the problem was caused by an obvious lost permission on the mongodb.lock file. I could solve the problem of changing the resolution with the following command:

 sudo chown mongodb:mongodb /var/lib/mongodb/mongodb.lock 

Following my research: step-by-step verification

+3
Nov 11 '15 at 23:24
source share

I understand that the question is about Ubuntu.

But if you get the same error on a Mac and don’t want $ sudo mongod work on a separate tab, you can do the following to fix the connection error if you have Homebrew -

 brew services start mongodb 

Based on the answer from this topic - Unable to connect to mongodb errno: 61 Connection refused

+3
Apr 27 '16 at 0:16
source share

In my case, bind_ip was not 127.0.0.1 in the /etc/mongodb.conf file, so change bind_ip to 127.0.0.1 (these can be comma-separated values, so make sure 127.0.0.1 is one of them). Then restart your system to take effect. Restart only for those who encounter

 $sudo service mongod restart Failed to restart mongod.service: Unit mongod.service not found. 
+3
Aug 17 '18 at 5:24
source share

very simple, just delete the file /var/lib/mongodb/mongodb.lock . after execution: mongo . finished

+1
Nov 16 '15 at 17:53
source share

Perhaps the data directory for mongo specified in /etc/mongod.conf is not a valid path.

Try double-checking the path if it really exists sudo vi /etc/mongod.conf and checking dbPath .

+1
Dec 01 '15 at 7:25
source share

I have the same error with you, this is my case:

 ~# mongod 2018-07-15T05:27:08.265+0000 I JOURNAL [initandlisten] journal dir=/data/db/journal 2018-07-15T05:27:08.265+0000 I JOURNAL [initandlisten] recover : no journal files present, no recovery needed 2018-07-15T05:27:08.301+0000 I JOURNAL [durability] Durability thread started 2018-07-15T05:27:08.301+0000 I JOURNAL [journal writer] Journal writer thread started 2018-07-15T05:27:08.302+0000 I CONTROL [initandlisten] MongoDB starting : pid=26796 port=27017 dbpath=/data/db 64-bit host=ubuntu-s-2vcpu-4gb-sfo2-01 2018-07-15T05:27:08.302+0000 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended. 2018-07-15T05:27:08.302+0000 I CONTROL [initandlisten] 2018-07-15T05:27:08.302+0000 I CONTROL [initandlisten] 2018-07-15T05:27:08.302+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. 2018-07-15T05:27:08.302+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never' 2018-07-15T05:27:08.302+0000 I CONTROL [initandlisten] 2018-07-15T05:27:08.302+0000 I CONTROL [initandlisten] db version v3.0.6 2018-07-15T05:27:08.302+0000 I CONTROL [initandlisten] git version: 1ef45a23a4c5e3480ac919b28afcba3c615488f2 2018-07-15T05:27:08.302+0000 I CONTROL [initandlisten] build info: Linux build6.ny.cbi.10gen.cc 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri Jan 3 21:39:27 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49 2018-07-15T05:27:08.302+0000 I CONTROL [initandlisten] allocator: tcmalloc 2018-07-15T05:27:08.302+0000 I CONTROL [initandlisten] options: {} 2018-07-15T05:27:08.308+0000 I NETWORK [initandlisten] waiting for connections on port 27017 

I type mongod to start the server and type control + c to exit the shell

then i type mongo and get

 ~# mongo MongoDB shell version: 3.0.6 connecting to: test 2018-07-15T05:05:02.738+0000 W NETWORK Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused 2018-07-15T05:05:02.739+0000 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 

As you can see, my error information is the same as yours.

In this case, mongod does not start from the backend process, when I type control + c , I exit mongod.

We can add the --fork arguments to make the process a process daemon.

 # mongod --logpath /usr/local/mongodb/log.txt --fork 

you must install --logpath if you want to use --fork

then you will be able to connect to Mongo

+1
Jul 15 '18 at 5:47
source share

Mongo 3. *. * - OSX - 2017

From README

 RUNNING 

Change the directory to mongodb-osx-x86_64-3. *. * / bin

To start a single server database:

 $ mkdir /data/db $ ./mongod 

Go to the new terminal

 $ # The mongo javascript shell connects to localhost and test database $ # by default -Run the following command in new terminal $ ./mongo > help 
0
Apr 23 '17 at 12:27
source share

I decided that simply by entering sudo mongo after the mongod .

0
Dec 06 '17 at 21:50
source share

I just uninstalled mongo following the instructions here: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/ And then I installed again following the instructions in this link. Everything worked without a glitch!

0
01 Feb '18 at 22:23
source share

Just a few thoughts on my case.

If you changed the dbPath and logPath directories to your custom values ​​(say / data / mongodb / data, / data / mongodb / log), you must assign them to mongodb, otherwise the non-existent / data / db / dir will be used.

 sudo chown -R mongodb:mongodb /data/mongodb/ sudo service mongod restart 
0
Jun 11 '18 at 2:46
source share

The latest version of MongoDB v 3.6.5 + made changes to the mongod.conf file

. That's how I fixed this problem on Mac OS High Sierra v 10.12.3

Note: I assume you installed / updated MongoDB using homebrew

mongo --version

 MongoDB shell version v3.6.5 git version: a20ecd3e3a174162052ff99913bc2ca9a839d618 OpenSSL version: OpenSSL 1.0.2o 27 Mar 2018 allocator: system modules: none build environment: distarch: x86_64 target_arch: x86_64 
  1. find mongod.conf file

      sudo find / -name mongod.conf' 

    /usr/local/etc/mongod.conf> first result.

  2. open the mongod.conf file

     sudo vi /usr/local/etc/mongod.conf 
  3. edit the file for remote access on the network: section

      port: 27017 bindIpAll: true #bindIp: 127.0.0.1 // comment this out 
  4. restart mongodb

    if you installed using brew than

     brew services stop mongodb brew services start mongodb 

otherwise kill the process.

  sudo kill -9 <procssID> 
0
Jun 22 '18 at 10:39
source share

The problem was with connecting to the database, this could be due to several reasons. For me, this was not enough space on my server, and when mongo tries to connect, it refuses due to lack of disk, check the local storage of your server using du -sh , if you have little space, check the size of the logs and take appropriate measures., The problem may exist due to the dbpath conflict in /etc/mongod.conf and the actual dbpath server starting with mongod If you encounter such a problem, please check my answer in the link below. stack overflow

0
Oct 30 '18 at 5:11
source share

For Mongo v3.6. 3+ (or 2019 versions)

 rm /var/lib/mongodb/mongod.lock service mongodb restart 
0
Aug 16 '19 at 8:08
source share

Follow these simple steps; (Works on MAC OS)

  1. Open a terminal and run sudo mongod

  2. Open a new terminal tab (do not close the tab of step 1) and run sudo mongo

It's all

0
Aug 22 '19 at 18:10
source share



All Articles