将收集索引驱动器创建为“ 30000毫秒后发生超时...”

时间:2019-06-07 11:17:39

标签: c# mongodb indexing

首先,我在Windows 10下使用独立的MongoDB服务器4.09,并使用Visual Studio Community 15.9.12开发。当未启用身份验证时,我的所有代码都能正常工作。我的目标是使我的代码在启用身份验证的情况下工作,因为它实际上无法为集合创建索引。

身份验证有效(如下面的代码所示),并且没有像该站点上大多数其他问题(如具有类似错误磁贴的问题)一样的麻烦

  

“使用CompositeServerSelector选择服务器30000ms之后发生超时” => A timeout occured after 30000ms selecting a server using CompositeServerSelector

当我尝试使用以下代码为集合创建索引时出现问题。

我不得不再次提及,该代码无需身份验证即可很好地工作,并且我为使用的db和经过身份验证的用户名添加了“ dbOwner”角色。

当未启用身份验证时,我使用类似这样的内容:

DBContext.client = new MongoClient(DBADRESS);

它工作正常。

启用身份验证后,我将使用类似这样的内容:

DBContext.client = new MongoClient("mongodb://username:password@localhost:27017/MatchbookDB");

它也很好。

集合索引有问题=>

DBContext.collections[CollectionName].Indexes.CreateOne(indexModel);

如果您问什么是DBContext,它的声明如下:

public static (MongoClient client, IMongoDatabase database, Dictionary<string, IMongoCollection<BsonDocument>> collections,
Dictionary<string, string> Commands) DBContext;

错误消息太长,但以:

开头
  

“使用CompositeServerSelector {选择器= MongoDB.Driver.MongoClient + AreSessionsSupportedServerSelector,LatencyLimitingServerSelector {AllowedLatencyRange = 00:00:00.0150000}}。选择服务器30000毫秒后发生超时。”。

我很惊讶,因为我原本会在身份验证步骤中预料到这种错误,而不是稍后。我当时以为是因为该数据库缺少用户角色,但是当我尝试使用“ dbOwner”为用户提供高级别的数据库权限时,却没有成功。

话虽如此,如果我们更深入地介绍错误列表,我们将提供更多信息:

  

“群集状态的客户端视图为{ClusterId:\“ 1 \”,ConnectionMode:\“ ReplicaSet \”,类型:\“ ReplicaSet \”,状态:\“ Disconnected \”,服务器:[{ServerId:\ “ {ClusterId:1,EndPoint:\” Unspecified / localhost:27017 \“} \”,EndPoint:\“ Unspecified / localhost:27017 \”,状态:\“ Disconnected \”,类型:\“ Unknown \”,HeartbeatException :\“ MongoDB.Driver.MongoConnectionException:打开与服务器的连接时发生异常。 ---> MongoDB.Driver.MongoAuthenticationException:无法使用sasl协议机制SCRAM-SHA-1进行身份验证。 ---> MongoDB.Driver.MongoCommandException:命令saslStart失败:身份验证失败。.\ r \ nàMongoDB.Driver.Core.WireProtocol.CommandUsingQueryMessageWireProtocol 1.ProcessReply(ConnectionId connectionId, ReplyMessage 1答复)\ r \ nàMongoDB.Driver.Core .WireProtocol.CommandUsingQueryMessageWireProtocol`1.d__14.MoveNext()\ r \ n ---“

我已经尝试了开头给出的问题的某些答案中给出的解决方案,但没有成功,即替换如下所示的连接字符串方法:

new MongoClient("mongodb://username:password@ds011111.mongolab.com:11111/db-name")

0 个答案:

没有答案