2

I am creating an API using MongoDB and Codeigniter. I want to connect to my database using an IP-address (not working) instead of using localhost (working fine). Because I need to have the MongoDB on a seperate server.

I tried to just change from localhost to the IP-address in the configuration file for the Codeigniter library but then I cannot connect.

I am using this Ci MongoDB library: https://github.com/alexbilbie/codeigniter-mongodb-library

How can I do this?

Nat
  • 3,587
  • 20
  • 22
Jonathan Clark
  • 19,726
  • 29
  • 111
  • 175
  • I'm having the exact same problem the error is just `Unable to connect to MongoDB` And localhost works, but ip doesn't – zidarsk8 Sep 20 '12 at 19:51

2 Answers2

0

Perhaps you need more info to know what the problem is.

You may specify mongo_supress_connect_error CodeIgniter configuration variable to false to enable verbose output of connection problem error.

kasuparu
  • 156
  • 1
  • 5
0

I am not a mongo db expert. But I could definitely say that you would need to use a host-name for the connections rather than using an ip-address.

The solution to the problem will be to add your remote server's ip address in the hosts file. In ubuntu, you could find it in /etc/hosts

edit like

10.xxx.xxx.xxx your-server-name

and save it

then you can always connect by replacing localhost with "your-server-name" (that you gave in hosts) in your syntax where you initiate your mongo db connection.

Guess this might not help you as you would have figured it out already. But might help someone who is searching for a similar question.

Mohammed Ashiq
  • 468
  • 4
  • 18