Mongodb C# 驱动程序 - 无法使用管理员身份验证访问其他数据库
当您在 MongoDB 控制台中以管理员用户(管理数据库的用户)身份登录时,您可以完全访问同一服务器上的任何数据库,而无需登录每个数据库。 但是,如果我使用官方 C# 驱动程序并向管理数据库提供连接字符串,那么当我尝试访问任何其他数据库时,我会收到身份验证错误。它发生在 MongoServerInstance.AcquireConnection() 中,它尝试重新验证连接并根据其他数据库检查管理数据库凭据,这当然会失败。
我想要实现的是 - 我提供管理连接字符串并访问所有数据库,而无需登录每个数据库,就像控制台所做的那样,
我可以做任何事情来使 C# 驱动程序以相同的方式工作就像控制台在身份验证方面所做的那样?
When you login as admin user (user of admin database) in MongoDB console, you can then have full access to any database on the same server without need to login to each of them.
But, if I use the official C# driver and provide connection string to admin database, then when I am trying to access any other database, I get authentication error. It's happening in MongoServerInstance.AcquireConnection() where it's trying to re-authenticate the connection and checks admin database credentials against the other database which of course fails.
What I'm trying to achieve is - I provide admin connection string and get access to all databases without the need to login to each and every one of them, exactly like the console does
Anything I can do to make C# driver work the same way as the console does in terms of authentication?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在深入研究 MongoDB 驱动程序的身份验证代码后,我发现您需要在连接字符串中的管理员用户名后面添加“(admin)”,以告诉驱动程序这实际上是管理员登录。这样做之后,一切都按预期进行!
After I digged into MongoDB driver's authentication code, I found that you need to add '(admin)' after admin username in the connection string to tell the driver that this is in fact an admin login. After doing that everything works as expected!