在使用启用身份验证的新部署的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应用程序中却不是这样。
发布于 2022-08-22 20:42:13
如果您查看一下C# MongoDB驱动程序在MongoCredential.cs#L469中的源代码,就会看到这个异常在检查auth机制时被抛出。
在连接字符串中指定确切的auth机制之后,所有异常都消失了!
示例:mongodb://USER:PASSWORD@HOST:27017/?authMechanism=SCRAM-SHA-256
希望其他人谷歌周围会发现我的答案有帮助!
编码愉快。
发布于 2022-09-27 17:16:11
对我来说,这只是将异常更改为unable to authenticate using sasl protocol mechanism scram-sha-256
经过一些尝试和错误之后,我通过将连接字符串更改为:
mongodb://USER:PASSWORD@HOST:27017/?authSource=admin
我不知道为什么默认情况下需要这样做,SCRAM-SHA-256连接字符串在其他上下文中运行良好.
https://stackoverflow.com/questions/73450818
复制相似问题