Bobcares

Mongodb connection refused in Ubuntu – How we fix quickly

by | Sep 15, 2019

MongoDB was running fine, but now it won't connect. Can you please fix it?

This is a common query we commonly receive from our MongoDB customers as part of our Server Management Services.

One of the most common causes for MongoDB connection refused in the Ubuntu server is conflicting server firewall rules.

Today, let’s get into the details and see how our Support Engineers fix MongoDB errors.

 

How we fix common MongoDB connection errors

At Bobcares, where we have more than a decade of expertise in managing servers, we see many customers facing problems while managing MongoDB.

In this particular case, the customer was trying to login via the MongoDB connection interface. All his attempts failed.

Now let’s see the major reasons for MongoDB errors and how our Support Engineers fix the top errors.

 

1. Firewall rule conflict

Recently, one of our customers had a problem with MongoDB. He had a Linode server running Ubuntu 16.04 LTS and MongoDB instance that he couldn’t connect to from an outside source. However, it could accept local connections.

Also, when he tried to run the command mongo databasedomain/databasename -u username -p password,he got an error looked like,

2019-07-22T23:54:03.093+0000 warning: Failed to connect to databaseserverip:27017, reason: errno:111 Connection refused
2019-07-22T23:54:03.094+0000 Error: couldn't connect to server < ip address >:27017 (databaseserverip), connection attempt failed at src/mongo/shell/mongo.js:148
exception: connect failed

On checking, our Support Engineers found that the error was due to a conflict of rules in the server firewall. So we opened MongoDB port correctly in UFW using

sudo ufw allow from client_ip_address to any port 27017

Further, we verify the connection using telnet too.

A successful telnet session will look like:

telnet 54.xx.xx.115 27017
Trying 54.xx.xx.115...
Connected to 54.xx.xx.115.
Escape character is '^]'.

 

2. Misconfiguration in mongod.conf file

Another reason for MongoDB to refuse connection can be the misconfiguration in /etc/mongod.conf.

Most of the customers may set bind_ip incorrectly and it will not allow the connection externally. So, our Support Engineers set the bind_ip = 0.0.0.0 in order to make successful external connections.

 

[Need assistance to fix Mongodb connection refused in ubuntu? We’ll help you.]

 

Conclusion

In short, the top most causes of this error Mongodb connection refused in Ubuntu are conflicting rules in the server firewall for the MongoDB port or bad settings in mongod.conf file. Today, we saw the various reasons for MongoDB errors and how our Support Engineers fix them.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

2 Comments

  1. nusaiba

    ● mongod.service – MongoDB Database Server
    Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
    Active: failed (Result: exit-code) since Tue 2020-06-02 13:26:38 UTC; 14min ago
    Docs: https://docs.mongodb.org/manual
    Process: 4121 ExecStart=/usr/bin/mongod –config /etc/mongod.conf (code=exited, status=14)
    Main PID: 4121 (code=exited, status=14)

    Jun 02 13:26:38 ubuntu-temp-183 systemd[1]: Started MongoDB Database Server.
    Jun 02 13:26:38 ubuntu-temp-183 mongod[4121]: 2020-06-02T13:26:38.828+0000 I STORAGE [main] Max cache overflow file size custom option: 0
    Jun 02 13:26:38 ubuntu-temp-183 systemd[1]: mongod.service: Main process exited, code=exited, status=14/n/a
    Jun 02 13:26:38 ubuntu-temp-183 systemd[1]: mongod.service: Failed with result ‘exit-code’.

    Reply
    • Sijin George

      Hello,
      MongoDB service is failing here. If you still have errors and need help, we’ll be happy to talk to you on chat (click on the icon at right-bottom).

      Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.