簡體   English   中英

嘗試連接到mongodb單節點副本集的超時異常

[英]Timeout exception trying to connect to mongodb single-node replica set

任何關於什么是錯的想法將不勝感激。 謝謝!

服務器啟動時帶有以下標志

mongodb-win32-x86_64-2008plus-ssl-4.0.2\bin\mongod --sslMode disabled --dbpath "C:\Users\foobar\AppData\Local\Temp\sj5ufivo.hgy" --port 27017  --bind_ip 127.0.0.1 --replSet singleNodeReplSet

申請代碼

MongoClient client = new MongoClient(@"mongodb://127.0.0.1:{0}/?connect=replicaSet;replicaSet=singleNodeReplSet".Formatted(port));
            var admin = client.GetDatabase("admin");
var replConfig = new BsonDocument(new List<BsonElement>()
            {
                new BsonElement("_id", "singleNodeReplSet"),
                new BsonElement("members", new BsonArray { new BsonDocument { { "_id", 0 }, { "host", "127.0.0.1:27017" } } })
            });
  var commandDocument = new BsonDocument("replSetInitiate", replConfig);
            var replSet = admin.RunCommand<BsonDocument>(commandDocument);

例外

System.TimeoutException
  HResult=0x80131505
  Message=A timeout occured after 30000ms 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 : "Connected", Servers : [{ ServerId: "{ ClusterId : 1, EndPoint : "127.0.0.1:27017" }", EndPoint: "127.0.0.1:27017", State: "Connected", Type: "ReplicaSetGhost", WireVersionRange: "[0, 7]" }] }.
  Source=MongoDB.Driver.Core
  StackTrace:
   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.MongoClient.AreSessionsSupportedAfterServerSelection(CancellationToken cancellationToken)
   at MongoDB.Driver.MongoClient.AreSessionsSupported(CancellationToken cancellationToken)
   at MongoDB.Driver.OperationExecutor.StartImplicitSession(CancellationToken cancellationToken)
   at MongoDB.Driver.MongoDatabaseImpl.UsingImplicitSession[TResult](Func`2 func, CancellationToken cancellationToken)
   at MongoDB.Driver.MongoDatabaseImpl.RunCommand[TResult](Command`1 command, ReadPreference readPreference, CancellationToken cancellationToken)

將連接類型更改為direct,將驅動程序更新為2.7.0,然后開始工作!

MongoClient client = new MongoClient(@"mongodb://127.0.0.1:{0}/?connect=direct;replicaSet=singleNodeReplSet".Formatted(port));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM