satya
satya

Reputation: 3560

Failed to connect mongoDB remotely from localhost using PHP

I need one help.I am unable to connect access mongodb remotely from localhost of my system using PHP. I am running mongoDB in ubuntu server using this 10.10.5.80 and i am trying to connect from my system localhost for that i used the following code.

$con=new MongoClient("mongodb://10.10.5.80:27017");

But unable to connect.I have already checked the whether that post is listening or not and its running in my ubuntu server.When i am pushing all my code to that particular ip(10.10.5.80) its working fine.Here i need to connect that remote mongoDB server from localhost.Please help me to resolve this issue.

Upvotes: 0

Views: 629

Answers (1)

Atish
Atish

Reputation: 4435

Please check following things in order to diagnose the issue:

  1. Try connecting remote mongodb server from mongo shell from your local machine:

    mongo --host 10.10.5.80 --port 27017

  2. If step 1 fails, try to check if the remote port 27017 is accessible from you local machine

    telnet 10.10.5.80 27017

  3. If both 1 and 2 fail, it confirms that the remote mongo server is not accessible from you server.

  4. Make sure your remote mongodb server is not bind to only 127.0.0.1(default), if that's the case you need to comment out the line in mongod.conf and restart the service.

  5. If your mongodb on hosted on cloud, then make sure there is a security group rule that allows your local machine to access the remote host.

  6. You can check mongodb logs/ mogostats if your requests from local machine adding up connections

Upvotes: 1

Related Questions