Mongodb C#驱动程序-无法使用管理员身份验证来访问其他数据库 [英] Mongodb C# driver - can't use admin authentication to access other databases

查看:156
本文介绍了Mongodb C#驱动程序-无法使用管理员身份验证来访问其他数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您在MongoDB控制台中以管理员用户(管理员数据库的用户)身份登录时,便可以完全访问同一服务器上的任何数据库,而无需登录每个数据库. 但是,如果我使用官方的C#驱动程序并提供到管理数据库的连接字符串,那么当我尝试访问任何其他数据库时,都会收到身份验证错误.这发生在MongoServerInstance.AcquireConnection()中,它试图重新验证连接并针对其他数据库(当然会失败)检查管理数据库凭据.

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

在身份验证方面,我能做些什么使C#驱动程序以与控制台相同的方式工作?

Anything I can do to make C# driver work the same way as the console does in terms of authentication?

推荐答案

在我深入研究了MongoDB驱动程序的身份验证代码之后,我发现您需要在连接字符串中的admin用户名后添加(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!

这篇关于Mongodb C#驱动程序-无法使用管理员身份验证来访问其他数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆