【问题标题】:MongoDB C# unable to connect to database: Unable to create an authenticatorMongoDB C# 无法连接到数据库:无法创建身份验证器
【发布时间】:2022-08-23 04:42:13
【问题描述】:

在使用启用了身份验证的新部署的 MongoDB 容器设置我的新环境时,我遇到了这个异常:\"An unhandled exception has occurred while executing the request. MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server. ---> System.NotSupportedException: Unable to create an authenticator.\"

在我的情况下,我正在使用像这个例子这样的连接字符串:mongodb://USER:PASSWORD@HOST:27017/?authMechanism=DEFAULT。该字符串在 MongoDB Compass 中运行良好,但在我的 .NET 6.0 应用程序中却没有。

    标签: c# mongodb mongodb-.net-driver


    【解决方案1】:

    如果您查看MongoCredential.cs#L469 中的 C# MongoDB 驱动程序的源代码,您会看到在检查身份验证机制时会引发此异常。

    在连接字符串中指定确切的身份验证机制后,所有异常都消失了!

    例如:mongodb://USER:PASSWORD@HOST:27017/?authMechanism=SCRAM-SHA-256

    希望其他在谷歌上搜索的人会发现我的回答很有帮助!

    快乐编码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-02
      • 2018-01-25
      • 1970-01-01
      • 2016-03-20
      • 1970-01-01
      • 2016-12-20
      • 1970-01-01
      • 2017-09-05
      相关资源
      最近更新 更多