Bobcares

MongoDB port 27017 not working – Rapid ways to fix it

by | Sep 13, 2019

While managing MongoDB, it’s very common to see Error: couldn’t connect to server 127.0.0.1:27017.

It’s loud and clear that Mongo shell couldn’t speak to the MongoDB server.

And the reasons for the error can be incorrect MongoDB settings, firewall restrictions and many more.

At Bobcares, we often get requests to fix MongoDB port 27017 not working error as part of our Server Management Services.

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

 

How we fix common MongoDB port errors

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

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

 

1. Incorrect IP or port

Recently, one of our customers contacted us with a problem related to MongoDB port connection. When the customer tried to restart the MongoDB, he was getting an error like,

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

Moreover, an attempt to access MongoDB tool resulted in the error:

In general, this happens when the address like host or IP was wrong or that it is not running on the server.

Therefore, our Database Engineers edited /etc/mongodb.conf and corrected the settings. We updated the bind IP of the MongoDB to accept connection from outside and also confirmed that the port 27017 is open.

That fixed the problem and MongoDB started accepting connections.

 

2. Insufficient storage space

Similarly, another customer had the same error, mongo MongoDB shell version: 2.4.9 connecting to: test Sun May 8 22:10:15.641 Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145 exception: connect failed while restarting the MongoDB.

Looking into the MongoDB log file, located in /var/log/mongodb/mongodb.log, we found the reason as

ERROR: Insufficient free space for journal files
Please make at least 3379MB available in /var/lib/mongodb/journal or use --smallfiles

This error occurs when the space allocated to disk is insufficient to store the journal files. Also, the journal allocation is required to store a minimum of 3 GB space to create and store journal files.

So, our Support Engineers solved the error by executing these steps.

We opened the startup file at  /etc/init.d/mongod and changed from

daemon –user “$MONGO_USER” $NUMACTL $mongod $OPTIONS –nounixsocket

to

daemon –user “$MONGO_USER” $NUMACTL $mongod $OPTIONS –nounixsocket –smallfiles

 

3. Problem with mongod service

Normally this error caused when didn’t start the mongod process before start mongo shell. So, our Support Engineers used the following steps to solve the error.

1. Initially, we removed the .lock file by executing

rm /var/lib/mongodb/mongod.lock

2. Then, we repaired the MongoDB

mongod –repair

3. After that, we started the mongod server

service mongod start

4. Finally, we started the mongo client

mongo

That’s it.

 

[Need assistance to fix MongoDB port errors? We’ll help you.]

 

Conclusion

In short, MongoDB port 27017 not working error may happen when there is insufficient storage space for journal files on disk or incorrect settings in the mongodb.conf file, firewall restrictions, etc. Today, we saw the various reasons for MongoDB port 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";

0 Comments

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.