Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-1670

Document the various connection modes

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Documentation
    • Labels:

      I used only one slave server in connection settings from the configured replica set:

      rs.status()
      { 
          "myState" : 2, 
          "members" : [
              { "name" : "localhost:31500", "state" : 1, "stateStr" : "PRIMARY", ... }, 
              { "name" : "localhost:31502", "state" : 7, "stateStr" : "ARBITER", ... }, 
              { "name" : "localhost:31501", "state" : 2, "stateStr" : "SECONDARY", ... } ], ...
      }
      

      Test code:

      Unable to find source-code formatter for language: csharp. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      var client = new MongoClient(new MongoClientSettings
      	{
      		ConnectionMode = ConnectionMode.Automatic,
      		Servers = new []{ MongoServerAddress.Parse("localhost:31501")}
      	});
      var result = client.GetDatabase("test").RunCommand<BsonDocument>(new BsonDocument() { { "connectionStatus", 1 } });
      

      I get an exception:

      System.TimeoutException: A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = ReadPreferenceServerSelector{ ReadPreference = { Mode = Primary, TagSets = [] } }, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 } }. Client view of cluster state is { ClusterId : "6", ConnectionMode : "Automatic", Type : "ReplicaSet", State : "Connected", Servers : [{ ServerId: "{ ClusterId : 6, EndPoint : "Unspecified/localhost:31502" }", EndPoint: "Unspecified/localhost:31502", State: "Connected", Type: "ReplicaSetArbiter", WireVersionRange: "[0, 3]" }] }.
         at MongoDB.Driver.Core.Clusters.Cluster.ThrowTimeoutException(IServerSelector selector, ClusterDescription description)
         at MongoDB.Driver.Core.Clusters.Cluster.WaitForDescriptionChangedHelper.HandleCompletedTask(Task completedTask)
         at MongoDB.Driver.Core.Clusters.Cluster.WaitForDescriptionChanged(IServerSelector selector, ClusterDescription description, Task descriptionChangedTask, TimeSpan timeout, CancellationToken cancellationToken)
         at MongoDB.Driver.Core.Clusters.Cluster.SelectServer(IServerSelector selector, CancellationToken cancellationToken)
         at MongoDB.Driver.Core.Bindings.ReadPreferenceBinding.GetReadChannelSource(CancellationToken cancellationToken)
         at MongoDB.Driver.Core.Operations.ReadCommandOperation`1.Execute(IReadBinding binding, CancellationToken cancellationToken)
         at MongoDB.Driver.OperationExecutor.ExecuteReadOperation[TResult](IReadBinding binding, IReadOperation`1 operation, CancellationToken cancellationToken)
         at MongoDB.Driver.MongoDatabaseImpl.ExecuteReadOperation[T](IReadOperation`1 operation, ReadPreference readPreference, CancellationToken cancellationToken)
         at MongoDB.Driver.MongoDatabaseImpl.RunCommand[TResult](Command`1 command, ReadPreference readPreference, CancellationToken cancellationToken)
      

      But if you specify another server name, the connection is established.

      Unable to find source-code formatter for language: csharp. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      var client = new MongoClient(new MongoClientSettings
      	{
      		ConnectionMode = ConnectionMode.Automatic,
      		Servers = new []{ MongoServerAddress.Parse("localhost:31501"), MongoServerAddress.Parse("unknown") }
      	});
      var result = client.GetDatabase("test").RunCommand<BsonDocument>(new BsonDocument() { { "connectionStatus", 1 } });
      

      But it does not work if I connect to a single server:

      • localhost:30000 - standalone
      Unable to find source-code formatter for language: csharp. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      var client = new MongoClient(new MongoClientSettings
      	{
      		ConnectionMode = ConnectionMode.Automatic,
      		Servers = new []{ MongoServerAddress.Parse("localhost:30000"), MongoServerAddress.Parse("unknown") }
      	});
      var result = client.GetDatabase("test").RunCommand<BsonDocument>(new BsonDocument() { { "connectionStatus", 1 } });
      

      How to connect with automatic mode to a variable number of servers?

            Assignee:
            Unassigned Unassigned
            Reporter:
            ExM Anatoliy Koperin
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: