0

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.

3
  • Is the port opened (allowed in iptables) on the remote machine? Commented May 7, 2016 at 7:14
  • yes,port has listen state while i typed command netstat -ntlup | grep LISTEN.its also running.Here i am tring to connect from my system's localhost. Commented May 7, 2016 at 7:17
  • Right now i checked using this command sudo iptable -L but did not find any port like 27017 there how to add here. Commented May 7, 2016 at 7:20

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

8 Comments

@ Astro : Let me to test first.
:i open cmd in my local system and checked your first two step for both case it gave me connection failed message.then mongodb is running in my local ubuntu server of that given IP.Can you provide the next step to resolve this issue.
@satya: please try step 4
@ Astro : Can you please give command to edit that file and restart the mongoDB again for Ubuntu.
1. vim /etc/mongod.conf 2. sudo service mongodb restart
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.