我在Azure中创建了一个使用Mongo API的Cosmos DB数据库。我已经创建了客户端并进行了以下配置-
_mongoDbConnectionString = configuration["MongoDBConnectionString"];
_databaseName = configuration["MongoDBName"];
_client = new MongoClient(_mongoDbConnectionString);
_database = _client.GetDatabase(_databaseName);
_collectionName = configuration["MongoDBCollectionName"];
然后尝试写入数据 -
_database.GetCollection<dynamic>(_collectionName).InsertOne(data);
遇到了以下错误-
使用CompositeServerSelector选择服务器时,在30000ms之后发生超时,其中CompositeServerSelector选择器包括MongoDB.Driver.MongoClient+AreSessionsSupportedServerSelector和LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 }。 客户端查看集群状态为{ ClusterId: "1",ConnectionMode: "ReplicaSet",Type: "ReplicaSet",State: "Disconnected",Servers:[{ ServerId:“ {ClusterId:1,EndPoint:“Unspecified / botframeworkcosmos.documents.azure.com:10255”}”,EndPoint:“ Unspecified / botframeworkcosmos.documents.azure.com:10255”,State:“ Disconnected”,Type:“ Unknown”,HeartbeatException:“ MongoDB.Driver.MongoConnectionException:在连接到服务器时发生异常 ---> System.Net.Internals.SocketExceptionFactory + ExtendedSocketException:连接尝试失败,因为已连接方在一段时间后未正确响应,或已建立的连接失败,因为连接的主机未能正确响应
我尝试了这个解决方案-使用CompositeServerSelector选择服务器时在30000ms之后出现超时,但没有成功。
我还尝试像这样设置SSL策略来配置客户端-
_mongoDbConnectionString = configuration["MongoDBConnectionString"];
_databaseName = configuration["MongoDBName"];
MongoClientSettings settings = MongoClientSettings.FromUrl(
new MongoUrl(_mongoDbConnectionString)
);
settings.SslSettings =
new SslSettings() { EnabledSslProtocols = SslProtocols.Tls12 };
_client = new MongoClient(settings);
_database = _client.GetDatabase(_databaseName);
_collectionName = configuration["MongoDBCollectionName"];
我仍然遇到同样的错误。奇怪的是,这段代码昨天都能正常工作。
更新: 我删除了数据库并创建了一个新的,但问题依旧存在。
你有什么想法,可能是什么问题导致的?
Unspecified/
在Unspecified/botframeworkcosmos.documents.azure.com:10255
前面看起来有点奇怪。 - Tsengmongodb://chatbotcosmos:<secret_key>@chatbotcosmos.documents.azure.com:10255/?ssl=true&replicaSet=globaldb
。这是我重新创建数据库后从Azure精确复制的新连接字符串。 - Souvik Ghoshbotframeworkcosmos.documents.azure.com
,而你的是chatbotcosmos.documents.azure.com
。 - Tseng/
,:
或者@
?因为它是一个URL(或者需要进行转义),所以你不能在密码中使用特殊字符。 - Tseng12pVpf5Y5spByBjHJkok2D0PfvaQYaTzmDGhZDXO96S0eH6RnQRuPkss4MksNYQjU6mx6d4YSbG3iajuFSkCxQ==
。这是我的旧密码,昨天还可以使用。 - Souvik Ghosh