I am using Mongo Db C# driver 2.11.5, and I have a static connection for the mongo client which I store globally. Sometimes the read operations fail. And it gives me error:
A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = WritableServerSelector, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 } }
Client view of cluster state is
{ ClusterId : "1",
ConnectionMode : "ReplicaSet",
Type : "ReplicaSet",
State : "Connected",
Servers :
[
{
ServerId: "{ ClusterId : 1, EndPoint : "mongo atlas Host 1" }",
EndPoint: "mongo atlas Host 1",
ReasonChanged: "Heartbeat",
State: "Connected",
ServerVersion: 4.2.11,
TopologyVersion: ,
Type: "ReplicaSetSecondary"
}
{ ServerId: "{ ClusterId : 1, EndPoint : "mongo atlas host 2", EndPoint: "mongo atlas host 2", ReasonChanged: "Heartbeat", State: "Connected", ServerVersion: 4.2.11, TopologyVersion: , Type: "ReplicaSetSecondary",
},
{ ServerId: "{ ClusterId : 1, EndPoint : "mongo atlas host 3 }", EndPoint: "mongo atlas host 3", ReasonChanged: "InvalidatedBecause:NoLongerPrimary", State: "Disconnected", ServerVersion: , TopologyVersion: , Type: "Unknown", LastHeartbeatTimestamp: null, LastUpdateTimestamp: "2021-01-15T16:35:37.9491599Z" }] }
So the main error which I am getting over here is
InvalidatedBecause: NoLongerPrimary.
In my connection string, I don’t have added readPrefference so it will be using readPrefference as Primary only.
Could someone Help me in how I can resolve this issue, or if there is something I am not doing correctly.