Mongodb C# driver - can't use admin authentication to access other databases

被刻印的时光 ゝ 提交于 2019-12-11 03:42:03

问题


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?


回答1:


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!



来源:https://stackoverflow.com/questions/6764078/mongodb-c-sharp-driver-cant-use-admin-authentication-to-access-other-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!