Mongodb C# driver - can't use admin authentication to access other databases
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 开发者_StackOverflow中文版as the console does in terms of authentication?
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!
精彩评论