1

First, i use a standalone MongoDB server 4.09 under windows 10 and develop with Visual Studio Community 15.9.12. All my code works fine when authentification is not enabled. My goal is to make my code work with authentification enabled as it actually fails on creating index for collections.

Authentification works well (as exposed in the code below) and does not have troubles like in most other questions on this site like the ones with similar errors tile

"A timeout occured after 30000ms selecting a server using CompositeServerSelector" => A timeout occured after 30000ms selecting a server using CompositeServerSelector.

The problem comes when i try to create an index for a collection with a code like the one below.

I have to mention again that the code works well without authentification and that i added the role "dbOwner" for the used db and for the username authentified.

When Authentification is not enabled, i use something like this :

DBContext.client = new MongoClient(DBADRESS);

It works fine.

When Authentification is enabled, i use something like this :

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

It works well too.

Problem with collection indexing =>

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

In case you ask what is DBContext, it's declared like this :

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

The error message is too long but it begins with :

"A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = MongoDB.Driver.MongoClient+AreSessionsSupportedServerSelector, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 } }. ...".

I'm surprised as i would have expected this kind of error at the authentification step, not later on. I was thinking it was because of lack of user role for this db but as i tried with "dbOwner" to give the user a high level of db rights but with no more success.

Having tsaid that, we have a little more info if we go a little deeper into the error listing :

"Client view of cluster state is { ClusterId : \"1\", ConnectionMode : \"ReplicaSet\", Type : \"ReplicaSet\", State : \"Disconnected\", Servers : [{ ServerId: \"{ ClusterId : 1, EndPoint : \"Unspecified/localhost:27017\" }\", EndPoint: \"Unspecified/localhost:27017\", State: \"Disconnected\", Type: \"Unknown\", HeartbeatException: \"MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server. ---> MongoDB.Driver.MongoAuthenticationException: Unable to authenticate using sasl protocol mechanism SCRAM-SHA-1. ---> MongoDB.Driver.MongoCommandException: Command saslStart failed: Authentication failed..\r\n à MongoDB.Driver.Core.WireProtocol.CommandUsingQueryMessageWireProtocol1.ProcessReply(ConnectionId connectionId, ReplyMessage1 reply)\r\n à MongoDB.Driver.Core.WireProtocol.CommandUsingQueryMessageWireProtocol`1.d__14.MoveNext()\r\n---"

I already tried without success the solution given in some answers of the question given at the beginning, ie replacing the connection string method in like below.:

new MongoClient("mongodb://username:password@ds011111.mongolab.com:11111/db-name")
Kynao
  • 83
  • 1
  • 11
  • 1
    Please format your post, this is unreadable I'm afraid. – DavidG Jun 07 '19 at 11:21
  • Do you have huge amount of data in this collection? – Dushyant Bangal Jun 07 '19 at 11:26
  • Have tried using the Async version of CreatOne? – Fildor Jun 07 '19 at 11:28
  • @DavidG is it better now ? If not please tell me what to improve next. – Kynao Jun 07 '19 at 12:46
  • @Dushyant Bangal : no very very few, it's a little test environment in which the amount of data is not important so no need to have a lot of data – Kynao Jun 07 '19 at 12:48
  • @Fildor : no, would you have an example? What could be the reason the non async version fails? – Kynao Jun 07 '19 at 12:49
  • Nevermind. If the dataset is small, then indexing shouldn't time out. It sounded like you are grounding the DB with _a lot_ of load while creating the index. – Fildor Jun 07 '19 at 12:52
  • @Fildor well it fails on the first create index call with no data while it works lile a charm without auth. Among my log we can see things like "MongoDB.Driver.MongoAuthenticationException: Unable to authenticate using sasl protocol mechanism SCRAM-SHA-1. --->" but i don't know how to resolve that – Kynao Jun 07 '19 at 12:59
  • Yes, I was thinking that maybe with auth, there is a session timing out or something like that. But I am really not sure. – Fildor Jun 07 '19 at 13:02
  • Did anyone find a proper solution to this? I'm currently experiencing the very same behavior of index creation working just fine without auth but timing out when using auth but I'm using the async index creation method. – Jonathan Oct 16 '21 at 08:41

0 Answers0