'MongoDB error network is unreachable' can occur due to many reasons that include network issues, if the mongo server is not started, etc.
Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to fix MongoDB errors.
In this context, we shall look into ways to resolve this MongoDB error message.
Here, you will learn some tips to resolve this error message.
One of our customers was using Robo 3T on Mac and came across this error message.
This is how we resolved this error message.
1. First, we tried to ping the mongo server to see whether we can get responses. If we get responses then there is something wrong set with the mongo config.
However, if we don't get responses then it means there is something wrong with the network.
Here, we were not getting any responses so we checked the DNS and the network gateway. For instance, if the DNS is 172.16.* and the network gateway (execute ifconig and check en0) is 172.17.*.
Also, if they don’t belong to the same network segment.
Thus, here the DNS cannot interpret the mongo host correctly. Someone may have polluted this DNS server.
So, to fix this issue we manually set DNS for the devices.
2. Another fix is, we access the bin folder present in the path C:\Program Files\MongoDB\Server\4.2\bin
Then, we open the command prompt at this location and run the below command and then try to connect with Robo 3T:
mongod
Also, we can create a data folder inside your C: drive & then create a DB named folder inside the data folder.
3. If the mongo server is not started then this error could occur. So restarting the database from the terminal can also fix this issue.
For that, we can run the below command:
mongod
This article covers methods to resolve the error 'MongoDB error network is unreachable' which can occur due to many reasons that include network issues, if the mongo server is not started, and so on.
To resolve this #MongoDB #error:
1. On Ubuntu server, to open mongo shell run:
$ mongo
2. Inside mongo shell, type following command to create new a admin user.
> use admin;
> db.createUser({user:"admin", pwd:"password", roles:[{ role: "root", db: "admin" }]});
3. By default mongodb is configured to allow connections only from localhost(IP 127.0.0.1).
We need to allow remote connections from any ip address. The following change should only be done in your development server. Open up etc/mongod.conf file and do the following change.
# network interfaces
net:
port: 27017
bindIp: 0.0.0.0 #default value is 127.0.0.1
Also in the same mongod.conf file uncomment security option and add authorization option as shown below:
security:
authorization: enabled
4. Save and exit the mongod.conf file and restart mongodb server:
$ sudo servcie mongod restart