17

I am trying to connect to mongolab from terminal via below command

 mongo ds061158.mongolab.com:61158/order_it -u <dbuser> -p <dbpassword>

I am getting the below error.

MongoDB shell version: 2.6.3
connecting to: ds061158.mongolab.com:61158/order_it
2014-07-09T13:52:44.890+0530 Error: couldn't connect to server ds061158.mongolab.com:61158 (23.22.170.205), connection attempt failed at src/mongo/shell/mongo.js:148
exception: connect failed

What has to be done in this case?

Thanks in Advance.

Hannan Shaik
  • 1,298
  • 2
  • 14
  • 27

3 Answers3

26

It looks like your network is blocking access to that port. I'd recommend contacting your network administrator or trying from a different network.

To test your network connectivity alone (no credentials necessary) you can run this command. This example was run from my unprivileged laptop just now and demonstrates a successful test.

% mongo ds061158.mongolab.com:61158
MongoDB shell version: 2.6.1
connecting to: ds061158.mongolab.com:61158/test
rs-ds061158:PRIMARY> db.runCommand({ping:1});
{ "ok" : 1 }
rs-ds061158:PRIMARY> exit
bye

Our full connectivity troubleshooting guide is here: http://docs.mongolab.com/connecting/#help

Also, feel free to contact us as support@mongolab.com if you'd like us to dig into the specifics of your server or code. We're always happy to help!

Regards,

Jared

jared
  • 5,369
  • 2
  • 21
  • 24
  • 2
    Thanks Jared. My firewall was preventing this. – Hannan Shaik Jul 10 '14 at 05:05
  • can you elaborate more on "network is blocking access to that port"? do you mean the open ports for my laptop? – Pierrew Jun 22 '15 at 05:45
  • @Pierrew: The issue could be anywhere between the client and the server. MongoLab does allow configuration of firewall rules for Dedicated plans, but that did not seem to be the issue here, as I was able to connect to the port from an unprivileged network. Often, local networks or even the OS you're running on your client will have outbound firewall rules. Your local network administrator will be able to help diagnose such situations and is probably the only person who can poke a hole in the firewall for you if needed. – jared Jun 26 '15 at 23:23
  • @jared can you look into this : http://stackoverflow.com/questions/41060880/mongoerror-failed-to-connect-to-server-on-first-connect – radio_head Feb 07 '17 at 15:20
0

I know this question is old, but in case someone still faces a similar issue, this is what helped me:

sudo rm /var/lib/mongodb/mongod.lock
sudo service mongodb restart
z_blue
  • 350
  • 3
  • 20
-2

You should try to explicitly specify the port you want to use with the --port option:

mongo ds061158.mongolab.com/order_it --port 61158 -u <dbuser> -p <dbpassword>

From the mongo man pages:

--port <port>
Specifies the port where the mongod or mongos instance is listening. Unless specified mongo connects to mongod instances on port 27017, which is the default mongod port.

Lix
  • 47,311
  • 12
  • 103
  • 131
  • 1
    No this does not work with URL. I got this error "MongoDB shell version: 2.6.3 url can't have host or port if you specify them individually" – Hannan Shaik Jul 09 '14 at 08:39
  • @hannanessay - yes... specify the port in a n option and remove it from your URL. – Lix Jul 09 '14 at 08:50
  • Command I used is this "mongo ds061158.mongolab.com/order_it --port 61158 -u -p " - I have removed the port from URL. Still I get the error "MongoDB shell version: 2.6.3 url can't have host or port if you specify them individually" – Hannan Shaik Jul 09 '14 at 08:58