When I create a MongoUrl
like this:
MongoUrl url = new MongoUrl("mongodb://mongoadmin:secret@localhost:27019/Testing");
I can access the DatabaseName
property without any issues.
However, when I use the following code to create a client:
var url = new MongoUrl("mongodb://mongoadmin:secret@localhost:27019/Testing");
var client = new MongoClient(url);
var database = client.GetDatabase(url.DatabaseName);
and try to list collections, I encounter the following authentication error:
Unhandled exception. MongoDB.Driver.MongoAuthenticationException: Unable to authenticate using sasl protocol mechanism SCRAM-SHA-1.
Interestingly, if I remove the database name from the connection string:
var url = new MongoUrl("mongodb://mongoadmin:secret@localhost:27019");
the authentication error does not occur.
It’s strange that I can access the DatabaseName
property from the MongoUrl
, but including the database name in the connection string results in an authentication error when creating and connecting to the client.