Mohammad_Hosseini
Mohammad_Hosseini

Reputation: 2599

Can't connect to host mongodb from homestead

I have a laravel 5.2 project on homestead 7 which works with mysql and mongodb, I have configured it to connect to host (my mac AMPPS) mysql and mongodb servers.

mysql is connected successfully but I can't connect to host mongodb from homestead.

when I try to connect to host mongodb server from homestead using mongo command I get below error :

vagrant@homestead:~$ mongo 192.168.10.1:27017/admin
MongoDB shell version: 3.2.18
connecting to: 192.168.10.1:27017/admin
2018-01-29T13:18:36.967+0000 W NETWORK  [thread1] Failed to connect to 192.168.10.1:27017, in(checking socket for error after poll), reason: errno:111 Connection refused
2018-01-29T13:18:36.968+0000 E QUERY    [thread1] Error: couldn't connect to server 192.168.10.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:231:14
@(connect):1:6

exception: connect failed

as you can see my host ip address is 192.168.10.1 and homestead ip address is 192.168.10.10.

And whenever I try to connect to mongodb from laravel mongodb driver I get below error message :

ConnectionTimeoutException in Collection.php line 174:
No suitable servers found (`serverSelectionTryOnce` set): [connection refused calling ismaster on '192.168.10.1:27017']

FYI : I used This shell script to install mongodb and it's driver on homestead 7 with php 7.1

Any suggestion how to fix this ?

Upvotes: 0

Views: 1471

Answers (1)

Mohammad_Hosseini
Mohammad_Hosseini

Reputation: 2599

The solution to this problem was to edit host /etc/mongodb.conf and set bind-ip to 0.0.0.0

bind_ip = 0.0.0.0

remember to restart mongodb server, then I connected to the host mongodb server.

Upvotes: 1

Related Questions