I'm trying to connect to MongoDB using a MONGO_URL:. This particular database has a username and password. I've created a user to allow readWrite commands and that's the one I'm using.

If I log into the database and use show dbs this is what appears:

admin         0.000GB
myspecial_db  0.000GB
local         0.000GB

I'm trying to access the myspecial_db.

MONGO_URL: mongodb://username:password@private-network-ip:27017/myspecial_db

When I try and launch my app I get this error in terminal.

MongoError: failed to connect to server [private-network-ip:27017]

What am I missing here?

  • 1
    Here a few quick things to check: Firewall settings, network proxy settings, double-quoting the connection string, the MongoDB database log. When you successfully connect to the database are you on the client (App side) or on the server? – John aka hot2use Sep 5 '18 at 6:32
  • When it works, as in a no firewall no username and password, it is connecting from the app side. This error is confusing Failed to connect to port 80 – bp123 Sep 5 '18 at 6:34
  • @bp123, What is MongoDB version(x,y,z)? – Md Haidar Ali Khan Sep 5 '18 at 7:13
  • It's MongoDB 3.4 – bp123 Sep 5 '18 at 7:22
  • In your comment you have mentioned port 80, Probably you are trying to access your application on web server and not the MongoDB. You need to try connecting to mongo shell from your application server and share the log. Alternatively you can directly share mongodb server log when you have attempted connection from your application. – Kapil Bhagchandani Sep 5 '18 at 19:16

As mention your error like

MongoError: failed to connect to server [private-network-ip:27017]

This error is what you would see if the mongo shell was not able to talk to the mongod server.

As per MongoDB documentation Connection String URI Format The URI format for defining connections between applications and MongoDB instances in the official MongoDB drivers.

The following is the standard URI connection scheme:


For further your ref here

| improve this answer | |

The problem I had wasn't related to the MONGO_URL it was related to server setup. I had blocked all incoming traffic using a firewall and the open port was incorrect.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.