30000ms在c#中使用CompositeServerSelector错误选择服务器后发生超时

时间:2019-02-12 11:45:51

标签: c# mongodb timeout

我正在尝试将一些数据发布到我的远程mongodb实例中,但是我收到一个超时异常,说打开与服务器的连接时发生了异常。

错误:

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 : "Automatic", 
    Type : "Unknown", 
    State : "Disconnected", 
    Servers : [{ 
        ServerId: "{ 
            ClusterId : 1, 
            EndPoint : "10.0.0.xxx:27017" 
        }", 
        EndPoint: "10.0.0.xxx:27017", 
        State: "Disconnected", 
        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.x:27017 
    }] 
}.

我尝试通过这两个选项连接到mongodb,但这无济于事。

1)

string username = "admin";
string password = "admin";
var settings = new MongoClientSettings
{
    Credential = credential,
    Server = new MongoServerAddress("10.0.0.xxx", 27017)
};
MongoClient dbClient = new MongoClient(settings);
IMongoDatabase db = dbClient.GetDatabase("test");
var ReportData = db.GetCollection<BsonDocument>("ReportData");
ReportData.InsertOne(document);

2)

MongoClient dbClient = new MongoClient("mongodb://admin:admin@127.0.0.x:27017/test");
IMongoDatabase db = dbClient.GetDatabase("test");
var ReportData = db.GetCollection<BsonDocument>("ReportData");
ReportData.InsertOne(document);

可能是什么问题?我是新来的。

0 个答案:

没有答案