Ubuntu: 14.04

MongodB version: 3.2.6

MongoDB shell version: 3.2.6 connecting to: test

2017-06-26T07:46:48.195+0000 W NETWORK  [thread1] Failed to connect to, reason: errno:111 Connection refused
2017-06-26T07:46:48.196+0000 E QUERY    [thread1] Error: couldn't connect to server, connection attempt failed :
@(connect):1:6 exception: connect failed

Hi guys,

Our service contains both mongodb and mongod service. We used to run mongod service (sudo service mongod start) however recently when re run mongod service, we got the error above.

However this problem didn't happen when we run mongodB service .

This is the mongod.conf file. Wonder who can give me some advice? Thanks!

  smallFiles: true
  dbPath: /var/lib/mongodb
    enabled: true

  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

  port: 27017
  bindIp: [,X.X.X.X]

        replSetName: rs0

6 Answers 6


It might be due to permission issues with your db directory (dbPath). You can try giving appropriate permission to your directory. Try the following steps:

  1. Give permission to /var/lib/mongodb directory.

    sudo chmod -R 0777 /var/lib/mongodb
  2. Try to start mongod service.

    sudo service mongod start
  3. Check status of mongod service.

    sudo service mongod status
  • changing permissions isn't correct , want to change owner to be mongodb user
    – Mike Q
    May 7, 2019 at 20:31
  • seems worked for me, but the directory has to be the one that's defined in by mongod.conf for the db Jul 20, 2021 at 17:08

Try the following:

sudo rm /var/lib/mongodb/mongod.lock
sudo mongod --repair
sudo service mongod start
sudo service mongod status

Double check you've not got conflicting rules in iptables.

Double check /etc/mongod.conf and check bind_ip = to allow external connections.


Check logs:

cat /var/log/mongodb/mongod.log

if you know the connection command try it:

mongo "mongodb://localhost/graylog"

If you see a core dump from this command (as root) look into changing permissions on /var/lib/mongodb ( change recursive ownership to mongodb:mongodb )

/usr/bin/mongod --config /etc/mongod.conf

Got it fixed by backup and completely removing Mongo data directory (in my case /var/lib/mongodb/). And after that, recreate database path using :

sudo mkdir -p /var/lib/mongodb/

sudo chown -R mongodb:mongodb /var/lib/mongodb/

This guy solved it: https://dba.stackexchange.com/a/252393/162290


You may try the following:

  1. remove the .lock file. sudo rm /var/lib/mongodb/mongod.lock

  2. grant the permission sudo chown -R mongodb:mongodb /var/lib/mongodb

  3. restart server sudo service mongod start


The format of bindIp is not correct.

If you want to have multiple IPs, you should do it like this:

  port: 27017
  • 1
    Hello and welcome to AskUbuntu! Looks like the correct format is indeed what the OP has: bindIp = [,,]. You might want to edit the answer. Sep 14, 2018 at 9:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .