Hi all, wondering if anybody can help diagnose an issue connecting to a replica set using the .NET driver.
Environment
1 x Ubuntu Server running MongoDB (3.6.2) replica set on ports 27001/27002/27003.
1 x Windows Server running app using MongoDB dotnet driver (2.12.2)
Both are dedicated servers running on a private network
Issue
The windows app can connect directly to the primary (27002) using the following connection string, this works fine and allows reads and writes without problem.
mongodb://username:password@ubuntu_host:27002/db_to_connect_to
I tried the following connection string combinations to connect to the replica set:
mongodb://username:password@ubuntu_host:27001,ubuntu_host:27002,ubuntu_host:27003/db_to_connect_to?replicaSet=replica_set_name
mongodb://username:password@ubuntu_host:27001,ubuntu_host:27002,ubuntu_host:27003/?authSource=db_to_connect_to&replicaSet=replica_set_name
Also tried using the IP address for the Ubuntu host instead of the domain name, but get the same error.
Error
System.TimeoutException
A timeout occurred after 30000 ms selecting a server using CompositeServerSelector {
Selectors = MongoDB.Driver.MongoClient + AreSessionsSupportedServerSelector, LatencyLimitingServerSelector {
AllowedLatencyRange = 00: 00: 00.0150000
}
}.
Client view of cluster state is {
ClusterId: "1",
ConnectionMode: "ReplicaSet",
Type: "ReplicaSet",
State: "Disconnected",
Servers: [{
ServerId: "{ ClusterId : 1, EndPoint : "
127.0 .0 .1: 27001 " }",
EndPoint: "127.0.0.1:27001",
ReasonChanged: "Heartbeat",
State: "Disconnected",
ServerVersion: ,
TopologyVersion: ,
Type: "Unknown",
HeartbeatException: "MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server. ---> System.Net.Sockets.SocketException:
No connection could be made because the target machine actively refused it 127.0.0.1:27001 at ...
The no connection error makes sense as it is trying to connect to 127.0.0.1 and on the Windows server this would refuse the connection, but why is the driver telling it to use the locahost instead of the host provided in the connection string.
Any thoughts?
Thanks,
James