I'm using MongoDB with replication(bitnami) on Azure.
I have created three mongodb nodes(1 primary ,1 secondary and 1 arbiter). When I try to connect with MongoDB connection URI (mongodb://username:password@ip01:27017,ip02:27017,ip03:27017/?readPreference=primary&replicaSet=replicaset)
it gives me error like pymongo.errors.ServerSelectionTimeoutError: 10.0.0.5:27017: timed out,10.0.0.6:27017: [Errno 113] No route to host,10.0.0.4:27017: timed out,10.0.0.7:27017: timed out
I prefered this Official Documentation (Bitnami) for connection url.
- 151
- 8
1 Answers
According to the document which you provided.
Ensure that the application is able to connect to each cluster node using its public or private IP address. To ensure connectivity, you have two options:
Host the application in the same network as the MongoDB cluster so that it can address each node using its private IP address. This is the recommended configuration for production environments. Host the application in a different network and assign public IP addresses, with appropriate firewall rules, to the cluster nodes (if not already assigned by default) so that the application can address each node using its public IP address. This configuration is not recommended for production environments.
So, if you test in the same Azure Virtual Network, you could use private IP(example 10.0.0.6). If you test it outside Azure, you should use Public IP address.
You could refer to this answer I provided.
Update:
If you want to connect your mongodb nodes, you should need ping the private IP. It is a design behavior.
If you want to mongodb from your app or local, you need create a Site-to-Site VPN connection or Point-to-Site VPN connection.
- 3,503
- 1
- 10
- 20
-
If you want to connect mongodb outside Azure VNet, you need create a VPN connection. I update my answer. – Shui shengbao Aug 15 '17 at 02:08
-
Bitnami Developer here. If you want to use the database from outside the VNet, then, as @walter-msft says, you should create a VPN. – Javier Salmeron Aug 15 '17 at 08:42